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

相关文章

Win10+GPU版Pytorch1.1安装的安装步骤

Win10+GPU版Pytorch1.1安装的安装步骤

安装cuda 更新nvidia驱动 打开GeForce Game Ready Driver或在GeForce Experience中下载符合自己gpu的程序。 选择cuda 打开nvi...

使用50行Python代码从零开始实现一个AI平衡小游戏

使用50行Python代码从零开始实现一个AI平衡小游戏

  集智导读: 本文会为大家展示机器学习专家 Mike Shi 如何用 50 行 Python 代码创建一个 AI,使用增强学习技术,玩耍一个保持杆子平衡的小游戏。所用环境为...

Django使用Jinja2模板引擎的示例代码

Django使用Jinja2模板引擎的示例代码

Jinja2模板引擎 安装Jinja2 :pip install jinja2,在应用目录下添加jinja2_env.py设定环境变量。 from django.contrib.s...

python 列表转为字典的两个小方法(小结)

1、现在有两个列表,list1 = ['key1','key2','key3']和list2 = ['1','2','3'],把他们转为这样的字典:{'key1':'1','key2':...

详解pandas.DataFrame中删除包涵特定字符串所在的行

详解pandas.DataFrame中删除包涵特定字符串所在的行

你在使用pandas处理DataFrame中是否遇到过如下这类问题?我们需要删除某一列所有元素中含有固定字符元素所在的行,比如下面的例子:   以上所述是小编给大家介绍的pa...