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实现自动发送邮件

自动发送邮件功能是我们经常要用到的,比如每天定时统计报表信息,然后自动发送给运营人员,协助运营人员进行业务数据分析。本文是用Python写的一个自动发送邮件的脚本,调用函数时,直接把发件...

python发布模块的步骤分享

python发布模块的步骤分享

1.为模块nester创建文件夹nester,其中包含:nester.py(模块文件): 复制代码 代码如下:"""这是"nester.py"模块,提供了一个名为print_lol()函...

Python实现的本地文件搜索功能示例【测试可用】

Python实现的本地文件搜索功能示例【测试可用】

本文实例讲述了Python实现的本地文件搜索功能。分享给大家供大家参考,具体如下: 偶尔需要搜索指定文件,不想每次都在windows下面去搜索,想用代码来实现搜索,而且能够收集搜索结果,...

Python功能点实现:函数级/代码块级计时器

工程中我们常常需要对某一个函数或者一块代码计时,从而监测系统关键位置的性能。计时方法是在代码块前后分别记录当前系统时间,然后两者相减得到代码块的耗时。最简单原始的实现类似: from...

python+unittest+requests实现接口自动化的方法

python+unittest+requests实现接口自动化的方法

前言: Requests简介 Requests 是使用Apache2 Licensed 许可证的 HTTP 库。用 Python 编写,真正的为人类着想。 Python 标准库中的 ur...