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

yipeiwu_com6年前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设计】。

相关文章

使用matplotlib画散点图的方法

如下所示: import matplotlib.pyplot as plt import numpy as np a = np.array([1,2,3,4]) b = np.arr...

python元组和字典的内建函数实例详解

本文实例讲述了python元祖和字典的内建函数。分享给大家供大家参考,具体如下: 元组Tuple 元组是序列类型一种,也是不可变类型数据结构,对元组修改后会生成一个新的元组。所以Tupl...

Python 实现opencv所使用的图片格式与 base64 转换

将np图片(imread后的图片)转码为base64格式 def image_to_base64(image_np): image = cv2.imencode('.jpg',...

Python字符串、列表、元组、字典、集合的补充实例详解

Python字符串、列表、元组、字典、集合的补充实例详解

本文实例讲述了Python字符串、列表、元组、字典、集合。分享给大家供大家参考,具体如下: 附加: python的很多编译器提供了代码补全功能,并且在填入参数时提供提示功能 字符串...

python读取文本绘制动态速度曲线

python读取文本绘制动态速度曲线

本文实例为大家分享了python读取文本绘制动态速度曲线的具体代码,供大家参考,具体内容如下 由于需要分析机械加工过程中各个轴的速度,于是用软件导出了数据,写了这个python脚本来显示...