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实现聊天机器人的示例代码

一、AIML是什么 AIML全名为Artificial Intelligence Markup Language(人工智能标记语言),是一种创建自然语言软件代理的XML语言,是由Ric...

基于python的列表list和集合set操作

基于python的列表list和集合set操作

以下是一些python的list和set的基本操作 1. list的一些操作 list = [1, 2, 3] list.append(5) print(list) list.e...

Python Matplotlib实现三维数据的散点图绘制

Python Matplotlib实现三维数据的散点图绘制

一、背景   近期项目即将开展,计划第一步就是实现数据的可视化,所以先学习一下数据展示相关Demo。选用Python2.7与Matplotlib来实现,平台采用Pycharm,值得一提的...

python机器学习之KNN分类算法

python机器学习之KNN分类算法

本文为大家分享了python机器学习之KNN分类算法,供大家参考,具体内容如下 1、KNN分类算法 KNN分类算法(K-Nearest-Neighbors Classification)...

python简单的函数定义和用法实例

本文实例讲述了python简单的函数定义和用法。分享给大家供大家参考。具体分析如下: 这里定义了一个温度转换的函数及其用法。 def convertTemp(temp, scale)...