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入门_学会创建并调用函数的方法

这篇文章主要介绍下如何创建并调用函数。 print():是打印放入对象的函数 len():是返回对象长度的函数 input():是让用户输入对象的函数 ... 简单来说,函数就是将对象放...

pycharm 主题theme设置调整仿sublime的方法

pycharm 主题theme设置调整仿sublime的方法

选择File->Settings 首先选择整体的theme 在font中scheme选择monokai,但是并不能进行更改,比如字体大小,如果要进行进一步地调整,选择save a...

python实现支付宝当面付(扫码支付)功能

本文实例为大家分享了python实现支付宝当面付示的具体代码,供大家参考,具体内容如下 一、配置信息准备 登录蚂蚁金服开放平台:https://open.alipay.com/platf...

Python中常见的数据类型小结

Python提供多种数据类型来存放数据项集合,主要包括序列(列表list和元组tuple),映射(如字典dict),集合(set),下面对这几种一一介绍: 一 序列 1.列表list 列...

Python3随机漫步生成数据并绘制

Python3随机漫步生成数据并绘制

本文为大家分享了Python3随机漫步生成数据并绘制的具体代码,供大家参考,具体内容如下 random_walk.py from random import choice #生成随...