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 获取一个文件夹内(包括子文件夹)所有文件的名字和路径 import os dir = "e:\\" for root, dirs, files in os.walk(d...

和孩子一起学习python之变量命名规则

变量命名规则 下面是关于变量名(也称为标识符)的一些规则 必须以一个字母或一个下划线字符开头。后面可以使用一个字母、数字或下划线字符的序列,长度不限。 字母可以是大写或小写,大小写...

Python 比较文本相似性的方法(difflib,Levenshtein)

最近工作需要用到序列匹配,检测相似性,不过有点复杂的是输入长度是不固定的,举例为: input_and_output = [1, 2, '你好', 世界', 12.34, 45.6,...

Ubuntu下使用Python实现游戏制作中的切分图片功能

Ubuntu下使用Python实现游戏制作中的切分图片功能

本文实例讲述了Ubuntu下使用Python实现游戏制作中的切分图片功能。分享给大家供大家参考,具体如下: why 拿到一个人物行走的素材,要用TexturePacker打包。Text...

python分析网页上所有超链接的方法

本文实例讲述了python分析网页上所有超链接的方法。分享给大家供大家参考。具体实现方法如下: import urllib, htmllib, formatter website =...