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 找出list中最大或者最小几个数的索引方法

如下所示: nums = [1,8,2,23,7,-4,18,23,24,37,2] result = map(nums.index, heapq.nlargest(3, nums)...

Anaconda入门使用总结

Anaconda入门使用总结

序 Python易用,但用好却不易,其中比较头疼的就是包管理和Python不同版本的问题,特别是当你使用Windows的时候。为了解决这些问题,有不少发行版的Python,比如WinPy...

Python2.7+pytesser实现简单验证码的识别方法

本文实例讲述了Python2.7+pytesser实现简单验证码的识别方法。分享给大家供大家参考,具体如下: 首先,安装Python2.7版本 然后,安装PIL工具,下载的地址是:htt...

django admin组件使用方法详解

关于admin: (1) admin的概述: admin是一个django子代的组件,当创建一个项目会后,就会在settings文件的 INSTALLED_APPS 中自动注册,另外在u...

Python实现文件按照日期命名的方法

本文实例讲述了Python实现文件按照日期命名的方法。分享给大家供大家参考。具体实现方法如下: 这里实现文件按照创建的时期批量重命名的功能 # -*- coding: utf-8 -...