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过滤txt文件内重复内容的方法

Python过滤txt文件内重复内容的方法

Python过滤txt文件内重复内容,并将过滤后的内容保存到新的txt中 示例如下 原文件 处理之后的文件 直接上代码 # -*-coding:utf-8 -*- f = o...

数组保存为txt, npy, csv 文件, 数组遍历enumerate的方法

数组保存为txt, npy, csv 文件, 数组遍历enumerate的方法

Numpy提供了几种数据保存的方法。 以3*4数组a为例: 1. a.tofile("filename.bin") 这种方法只能保存为二进制文件,且不能保存当前数据的行列信息,文件后缀不...

pandas 把数据写入txt文件每行固定写入一定数量的值方法

pandas 把数据写入txt文件每行固定写入一定数量的值方法

我遇到的情况是:把数据按一定的时间段提出。比如提出每天6:00-8:00的每个数据,可以这样做: # -*-coding: utf-8 -*- import pandas as pd...

Python实现的微信公众号群发图片与文本消息功能实例详解

本文实例讲述了Python实现的微信公众号群发图片与文本消息功能。分享给大家供大家参考,具体如下: 在微信公众号开发中,使用api都要附加access_token内容。因此,首先需要获取...

django rest framework vue 实现用户登录详解

django rest framework vue 实现用户登录详解

后端代码就不介绍了,可以参考 django rest framework 实现用户登录认证 这里介绍一下前端代码,和前后端的联调过程 在components下新建login.vue 文件...