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 matplotlib 注释文本箭头简单代码示例

python matplotlib 注释文本箭头简单代码示例

注释文本箭头 结果展示: 完整代码示例: import numpy as np import matplotlib.pyplot as plt fig, ax = plt.sub...

Python + Requests + Unittest接口自动化测试实例分析

Python + Requests + Unittest接口自动化测试实例分析

本文实例讲述了Python + Requests + Unittest接口自动化测试。分享给大家供大家参考,具体如下: 1. 介绍下python的requests模块 Python Re...

Python清空文件并替换内容的实例

有个文本文件,需要替换里面的一个词,用python来完成,我是这样写的: def modify_text(): with open('test.txt', "r+") as f:...

从源码解析Python的Flask框架中request对象的用法

from flask import request Flask 是一个人气非常高的Python Web框架,笔者也拿它写过一些大大小小的项目,Flask 有一个特性我非常的喜欢,就是无论...

python pygame实现挡板弹球游戏

python pygame实现挡板弹球游戏

学了一天pygame,用python和pygame写一个简单的挡板弹球游戏 GitHub: EasyBaffleBallGame # -*- coding:utf-8 -*- fr...