python将pandas datarame保存为txt文件的实例

yipeiwu_com5年前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将文本分每两行一组并保存到文件

python将文本分每两行一组并保存到文件

业务需求 需要将文本文件分每两行一组 jb51.txt 1:www.jb51.net 2:www.jb51.net 3:www.jb51.net 4:www.jb51.net 5:ww...

Python 最强编辑器详细使用指南(PyCharm )

Python 最强编辑器详细使用指南(PyCharm )

作者:Jahongir Rahmonov 机器之心编译 参与:魔王 PyCharm 是一种 Python IDE,可以帮助程序员节约时间,提高生产效率。那么具体如何使用呢?本文从 PyC...

linux安装python修改默认python版本方法

linux安装python修改默认python版本方法

linux默认是安装了python,默认是安装python2.6.6,可能安装的版本是不能符合我们需要的python要求的。我们需要重新安装python的版本,今天演示一下安装pytho...

图解Python变量与赋值

图解Python变量与赋值

Python是一门独特的语言,与C语言有很大区别,初学Python很多萌新表示对变量与赋值不理解,学过C的都知道,给变量赋值时,需要先指定数据类型,同时会开辟一块内存区域,用于存储值,例...

python友情链接检查方法

本文实例讲述了python友情链接检查方法。分享给大家供大家参考。具体实现方法如下: # _*_ coding:utf-8 _*_ #xiaohei.python.seo.call....