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之参数,定义时小括号中的参数,用来接收参数用的,称为 “形参” 调用时小括号中的参数,用来传递给函数用的,称为 “实参”。 1、思考一个问题,如下: 现在需要定义一个函数,这...

Python实现在Linux系统下更改当前进程运行用户

在上一篇文章中,我们讲了如何在linux上用python写一个守护进程。主要原理是利用linux的fork函数来创建一个进程,然后退出父进程运行,生成的子进程就会成为一个守护进程。细心观...

详解Python:面向对象编程

面向过程的程序设计把计算机程序视为一系列的命令集合,即一组函数的顺序执行。为了简化程序设计,面向过程把函数继续切分为子函数,即把大块函数通过切割成小块函数来降低系统的复杂度 python...

基于python实现自动化办公学习笔记(CSV、word、Excel、PPT)

1、CSV (1)写csv文件 import csv def writecsv(path,data): with open(path, "w") as f: wri...

python操作oracle的完整教程分享

1. 连接对象 操作数据库之前,首先要建立数据库连接。 有下面几个方法进行连接。 >>>import cx_Oracle >>>db = cx_O...