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

相关文章

浅析PHP与Python进行数据交互

最近,决定在一个项目用tp5进行APP接口开发,用Python做数据分析,然后这就面临一个问题:PHP和Python如何进行数据交互? 思路 我解决此问题的方法是利用了PHP的pas...

使用numpy和PIL进行简单的图像处理方法

如下所示: from PIL import Image import numpy as np # 反相 # a = np.array(Image.open("test.jpg"))...

Series和DataFrame使用简单入门

Series和DataFrame使用简单入门

(1)、导入库 from pandas import Series,DataFrame import pandas import numpy (2)、Series简单创建与使用...

Python中enumerate()函数编写更Pythonic的循环

enumerate函数 enumerate是一个Python内置函数,一个功能强大的内置函数。其实功能强大不足以形容它, 但是很难用一个词来形容它的用途。 让我们来看看一个使用enum...

在Python中调用Ping命令,批量IP的方法

如下所示: #!/usr/bin/env python #coding:UTF-8 ''''''' Author: jefferchen@163.com 可在命令行直接带目的IP...