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脚本在Nginx和uwsgi上部署MoinMoin的教程

在 CentOS 下使用 apache+mod_wsgi 部署了 MoinMoin,但是编辑和保存页面很慢,于是准备使用 nginx+uwsgi 重新部署 本文假定已经按照官方指引 Qu...

Python中时间datetime的处理与转换用法总结

python中日期类datetime功能比较强大,使用起来很方便,把常用的两种用法总结如下: from datetime import datetime from datetime...

使用PyCharm配合部署Python的Django框架的配置纪实

使用PyCharm配合部署Python的Django框架的配置纪实

安装软件 安装 Python 2.7、PyCharm、pip(Python包管理工具)、Django ( pip install Django) 部署 PyCharm 新建Django工...

python机器学习理论与实战(六)支持向量机

python机器学习理论与实战(六)支持向量机

上节基本完成了SVM的理论推倒,寻找最大化间隔的目标最终转换成求解拉格朗日乘子变量alpha的求解问题,求出了alpha即可求解出SVM的权重W,有了权重也就有了最大间隔距离,但是其实上...

Python批量修改文件后缀的方法

Python批量修改文件后缀的方法

近期下载了很多各种教程, 但是不幸的是后缀名都是 ".mp4", 而本人喜欢 ".rmvb" 后缀,由于有轻微洁癖, 受不了后面的 ".mp4" 缀, 但是手动修改又太过繁琐, 所以用近...