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设计】。

相关文章

python3转换code128条形码的方法

这年头如果用 python3 做条形码的,肯定(推荐)用 pystrich 。 这货官方文档貌似都没写到支持 Code128 ,但是居然有这个类( Code128Encoder )。。。...

Django自定义用户登录认证示例代码

Django自定义用户登录认证示例代码

前言 有时候 Django 自带的用户登录认证不能满足我们的需求,比如我不想要用户名+密码登录,我想手机号+验证码登录,这样就需要我们去修改 Django 自带的认证了。 Django...

DES加密解密算法之python实现版(图文并茂)

DES加密解密算法之python实现版(图文并茂)

一、DSE算法背景介绍 1. DES的采用 1979年,美国银行协会批准使用 1980年,美国国家标准局(ANSI)赞同DES作为私人使用的标准,称之为DEA(ANSI X.392) 1...

python3调用百度翻译API实现实时翻译

今天需要做一个翻译的工具,找到之前写过的有道翻译,已经不能用了,最后看到百度翻译还不错,不过官方版本是Python2,我需要Python3,就自己写了一个: # coding: ut...

使用python制作一个解压缩软件

使用python制作一个解压缩软件

python实现解压缩的重要模块就是——zipfile,其次是os 安装zipfile模块 首先得安装zipfile模块,打开cmd输入一下命令即可安装 pip install zipf...