python将pandas datarame保存为txt文件的实例

yipeiwu_com5年前Python基础

CSV means Comma Separated Values. It is plain text (ansi).

The CSV ("Comma Separated Value") file format is often used to exchange data between disparate applications. The file format, as it is used in Microsoft Excel, has become a pseudo standard throughout the industry, even among non-Microsoft platforms.

TXT is not really a file format, and it could mean multiple things in different contexts. Generally you export tables in either CSV (comma separated values) or TSV (tab separated values). Which you should choose depends mainly on your data: if your data has commas in it but not tabs, you should go for TSV.

# -*- coding: UTF-8 -*-
import sys
import json
reload(sys)
sys.setdefaultencoding('utf-8')
 
import pandas as pd
import numpy as np
 
 
#读取excel保存成txt格式
excel_file = pd.read_excel("text.xlsx")
excel_file.to_csv('excel2txt.txt', sep='\t', index=False)

参考:https://stackoverflow.com/questions/41428539/data-frame-to-file-txt-python/41514539

以上这篇python将pandas datarame保存为txt文件的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

使用C#配合ArcGIS Engine进行地理信息系统开发

使用C#配合ArcGIS Engine进行地理信息系统开发

简单的地图读取、展示 终于到暑假了。。。开始认真整理整理相关学习的心得体会咯~ 先把很久之前挖的关于C# 二次开发的坑给填上好了~ 这次先计划用一个月把C# ArcEngine 10.0...

python 列表推导式使用详解

所谓的列表推导式,就是指的轻量级循环创建列表。 基本使用方式 # 创建一个0-10的列表 a = [x for x in range(11)] print(a) """ 输出结果:...

python 实现二维列表转置

python 二维列表转置 def transpose(self, matrix): new_matrix = [] for i in range(len(matri...

python 读取目录下csv文件并绘制曲线v111的方法

实例如下: # -*- coding: utf-8 -*- """ Spyder Editor This temporary script file is located here:...

Python适配器模式代码实现解析

Python适配器模式,代码,思考等 # -*- coding: utf-8 -*- # author:baoshan class Computer: def __init__(...