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

相关文章

selenium使用chrome浏览器测试(附chromedriver与chrome的对应关系表)

selenium使用chrome浏览器测试(附chromedriver与chrome的对应关系表)

使用WebDriver在Chrome浏览器上进行测试时,需要从http://chromedriver.storage.googleapis.com/index.html网址中下载与本机c...

Python中GeoJson和bokeh-1的使用讲解

Python中GeoJson和bokeh-1的使用讲解

GeoJson 文档 { "type": "FeatureCollection", "features": [ { "geometry": { "type":...

Python实现TCP协议下的端口映射功能的脚本程序示例

Python实现TCP协议下的端口映射功能的脚本程序示例

1 端口映射 举个例子来说明一下端口映射的作用。 有A、B、C三台计算机,A、B互通,B、C互通,但是A、C不通,这个时候在C上开了一个Web服务,如何让A访问C的Web服务? 最简单有...

python查看列的唯一值方法

查看某一列中有多少中取值: 数据集名.drop_duplicates(['列名']) #实际为删除重复项,删除后对原数据集不修改 输入:data.drop_duplicates(['na...

修改Pandas的行或列的名字(重命名)

pandas.DataFrame.rename 使用函数: DataFrame.rename(mapper=None, index=None, colum...