python将pandas datarame保存为txt文件的实例

yipeiwu_com5年前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实现的井字棋(Tic Tac Toe)游戏示例

Python实现的井字棋(Tic Tac Toe)游戏示例

本文实例讲述了Python实现的井字棋(Tic Tac Toe)游戏。分享给大家供大家参考,具体如下: 说明 用python实现了井字棋,整个框架是本人自己构思的,自认为比较满意。另外,...

python中随机函数random用法实例

本文实例讲述了python中随机函数random用法。分享给大家供大家参考。具体如下: python中的random模块功能非常强大,可以生成各种随机值 #! python # ra...

PyQt5每天必学之工具提示功能

PyQt5每天必学之工具提示功能

本文将教会我们如何使用PyQt5控件的工具提示功能。 #!/usr/bin/python3 # -*- coding: utf-8 -*- """ PyQt5 教程 这个例子显示...

python 读写文件,按行修改文件的方法

如下所示: >>> f = open(r'E:\python\somefile.txt','w') 打开文件,写模式 >>> f.write...

Python基础语言学习笔记总结(精华)

Python基础语言学习笔记总结(精华)

以下是Python基础学习内容的学习笔记的全部内容,非常的详细,如果你对Python语言感兴趣,并且针对性的系统学习一下基础语言知识,下面的内容能够很好的满足你的需求,如果感觉不错,就收...