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

相关文章

python中的数据结构比较

列表:list=[val1,val2] 1.列表中的每一个元素都是可变的,有序的,可以被查看索引的。 可变意味着可以对每个元素进行增删改查的操作,列表中的元素可以是Python中的任...

python SVM 线性分类模型的实现

python SVM 线性分类模型的实现

运行环境:win10 64位 py 3.6 pycharm 2018.1.1 导入对应的包和数据 import matplotlib.pyplot as plt import num...

git使用.gitignore设置不生效或不起作用问题的解决方法

偶然遇到的问题,记录如下: 通常我们在push项目时,会有些配置文件或本地文件不想上传到服务器上 这时候我们会通过设置.gitignore  文件 一般设置成这样: ###...

python reverse反转部分数组的实例

python3中,list有个reverse函数,用来反转列表元素,但是如果想要反转部分元素呢? a = [1,2,3,4,5] a[0:3].reverse() # not wor...

python difflib模块示例讲解

python difflib模块示例讲解

difflib模块提供的类和方法用来进行序列的差异化比较,它能够比对文件并生成差异结果文本或者html格式的差异化比较页面,如果需要比较目录的不同,可以使用filecmp模块。 clas...