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将字符串以utf-8格式保存在txt文件中的方法

python将字符串以utf-8格式保存在txt文件中的方法

如下所示: #ltp_data 字符串 写进777.txt 1、 def save(filename, contents): fh = open(filename, 'w',...

详解Python核心对象类型字符串

Python的字符串的特点 Python与C语言,Java语言都不一样,没有单个字符,只有一个有一个字符的字符串。 字符串对象不可修改,属于不可变类型 字符串和列表,元组都...

Python常用时间操作总结【取得当前时间、时间函数、应用等】

本文实例讲述了Python常用时间操作。分享给大家供大家参考,具体如下: 我们先导入必须用到的一个module >>> import time 设置一个时间的...

10个Python面试常问的问题(小结)

概述 Python是个非常受欢迎的编程语言,随着近些年机器学习、云计算等技术的发展,Python的职位需求越来越高。下面我收集了10个Python面试官经常问的问题,供大家参考学习。 类...

Python制作动态字符图的实例

Python制作动态字符图的实例

这次我们拿小龙猫来做演示 这里就不必多说了,也就导入几个用到的包: SOURCE_PATH:这个是GIF的路径OUTPUT_PATH:这个是每一帧的存放路径FRAMES_PATH:这...