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实现的金山快盘的签到程序

复制代码 代码如下:__author__ = 'clownfish'#coding:utf-8import urllib2,urllib,cookielib,json username...

Django与JS交互的示例代码

Django与JS交互的示例代码

应用一:有时候我们想把一个 list 或者 dict 传递给 javascript,处理后显示到网页上,比如要用 js 进行可视化的数据。 请注意:如果是不处理,直接显示在网页上,用Dj...

python3编写C/S网络程序实例教程

本文以实例形式讲述了python3编写C/S网络程序的实现方法。具体方法如下: 本文所述实例是根据wingIDE的提示编写的一个C/S小程序,具体代码如下: client端myclien...

基于python脚本实现软件的注册功能(机器码+注册码机制)

一、前言: 目的:完成已有python图像处理工具的注册功能 功能:用户运行程序后,通过文件自动检测认证状态,如果未经认证,就需要注册。注册过程是用户将程序运行后显示的机器码(C盘的卷序...

python 获取指定文件夹下所有文件名称并写入列表的实例

如下所示: import os import os.path rootdir = "./pic_data" file_object = open('train_list.txt','...