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 pandas.DataFrame选取、修改数据最好用.loc,.iloc,.ix实现

相信很多人像我一样在学习python,pandas过程中对数据的选取和修改有很大的困惑(也许是深受Matlab)的影响。。。 到今天终于完全搞清楚了!!! 先手工生出一个数据框吧 i...

使用python 获取进程pid号的方法

保存为.py文件后 运行脚本在后面添加进程名称即可 比如:python proinfo.py qq 即可获取QQ的进程信息,注意不区分大小写 复制代码 代码如下:#-*- encodin...

安装Pycharm2019以及配置anconda教程的方法步骤

安装Pycharm2019以及配置anconda教程的方法步骤

一、获取安装包: Pycharm 官网 下载页面 :点击打开 Anconda 官网 下载页面 :点击打开 选择对应的系统和需要的版本进行下载,pycharm 分为付费专业版和社区免...

Python字符串逆序输出的实例讲解

1、有时候我们可能想让字符串倒序输出,下面给出几种方法 方法一:通过索引的方法 >>> strA = "abcdegfgijlk" >>> str...

详解Python发送email的三种方式

详解Python发送email的三种方式

Python发送email的三种方式,分别为使用登录邮件服务器、使用smtp服务、调用sendmail命令来发送三种方法 Python发送email比较简单,可以通过登录邮件服务来发送...