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 字符串中的字符倒转

方法一,使用[::-1]: s = 'python' print s[::-1] 方法二,使用reverse()方法: l = list(s) l.reverse() print ''....

Pyhton中单行和多行注释的使用方法及规范

Pyhton中单行和多行注释的使用方法及规范

前言 注释可以起到一个备注的作用,团队合作的时候,个人编写的代码经常会被多人调用,为了让别人能更容易理解代码的通途,使用注释是非常有效的。 Python  注释符 一、py...

python 使用pygame工具包实现贪吃蛇游戏(多彩版)

python 使用pygame工具包实现贪吃蛇游戏(多彩版)

今天我们用python和python的工具包pygame来编写一个贪吃蛇的小游戏 贪吃蛇游戏功能介绍 贪吃蛇的游戏规则如下: 通过上下左右键或者WASD键来移动蛇来,让它吃到食物,...

TF-IDF算法解析与Python实现方法详解

TF-IDF算法解析与Python实现方法详解

TF-IDF(term frequency–inverse document frequency)是一种用于信息检索(information retrieval)与文本挖掘(text m...

Python中的id()函数指的什么

Python官方文档给出的解释是 id(object) Return the “identity” of an object. This is an integer (or long i...