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开发app实战的方法

利用python开发app实战的方法

我很早之前就想开发一款app玩玩,无奈对java不够熟悉,之前也没有开发app的经验,因此一直耽搁了。最近想到尝试用python开发一款app,google搜索了一番后,发现确实有路可寻...

Django应用程序中如何发送电子邮件详解

Django应用程序中如何发送电子邮件详解

前言 在Django应用程序中发送电子邮件最常见的用例是密码重置、帐户激活和发送与您的应用程序相关的一般通知。下面来看看详细的介绍吧。 配置Django发送电子邮件 要配置您的Djang...

python提取具有某种特定字符串的行数据方法

python提取具有某种特定字符串的行数据方法

今天又帮女朋友处理了一下,她的实验数据,因为python是一年前经常用,最近找工作,用的是c,c++,python的有些东西忘记了,然后就一直催我,说我弄的慢,弄的慢,你自己弄啊,烦不烦...

Flask框架中request、请求钩子、上下文用法分析

本文实例讲述了Flask框架中request、请求钩子、上下文用法。分享给大家供大家参考,具体如下: request 就是flask中代表当前请求的request对象: 常用的属性如下:...