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

相关文章

kafka监控获取指定topic的消息总量示例

我就废话不多说了,直接 上代码吧! import kafka.api.PartitionOffsetRequestInfo; import kafka.common.TopicAnd...

Python Web框架Tornado运行和部署

本文实例为大家分享了Python Web框架Tornado运行和部署的详细内容,供大家参考,具体内容如下 一、运行和部署 因为Tornado内置了自己的HTTPServer,运行和部署它...

numpy.linspace 生成等差数组的方法

numpy.linspace 生成等差数组的方法

如下所示: numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None) start:...

Python实现图片滑动式验证识别方法

Python实现图片滑动式验证识别方法

1 abstract 验证码作为一种自然人的机器人的判别工具,被广泛的用于各种防止程序做自动化的场景中。传统的字符型验证安全性已经名存实亡的情况下,各种新型的验证码如雨后春笋般涌现。目前...

python去掉行尾的换行符方法

如下所示: mystring.strip().replace(' ', '').replace('\n', '').replace('\t', '').replace('\r', '')...