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中Django发送带图片和附件的邮件

Python中Django发送带图片和附件的邮件

最近需要做集团的SRC系统。暂无安全研发,所以只能找我这个小菜兼职开发。系统使用Django框架,在整个过程中,有许多奇特的需求。在某项需求中,需要给厂商用户发送富文本邮件,漏洞详情,这...

基于wxpython开发的简单gui计算器实例

本文实例讲述了基于wxpython开发的简单gui计算器。分享给大家供大家参考。具体如下: # wxCalc1 a simple GUI calculator using wxPyt...

Python二叉树的遍历操作示例【前序遍历,中序遍历,后序遍历,层序遍历】

本文实例讲述了Python二叉树的遍历操作。分享给大家供大家参考,具体如下: # coding:utf-8 """ @ encoding: utf-8 @ author: lixia...

tensorflow 打印内存中的变量方法

法一: 循环打印 模板 for (x, y) in zip(tf.global_variables(), sess.run(tf.global_variables())): pri...

python实现在pandas.DataFrame添加一行

实例如下所示: from pandas import * from random import * df = DataFrame(columns=('lib', 'qty1', 'q...