python將pandas datarame保存為txt文件的實(shí)例
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文件的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
使用Python實(shí)現(xiàn)簡(jiǎn)單的人臉識(shí)別功能(附源碼)
Python中實(shí)現(xiàn)人臉識(shí)別功能有多種方法,依賴于python膠水語言的特性,我們通過調(diào)用包可以快速準(zhǔn)確的達(dá)成這一目的,本文給大家分享使用Python實(shí)現(xiàn)簡(jiǎn)單的人臉識(shí)別功能的操作步驟,感興趣的朋友一起看看吧2021-12-12
解讀Scrapy回調(diào)函數(shù)callback傳遞參數(shù)的方式
這篇文章主要介紹了解讀Scrapy回調(diào)函數(shù)callback傳遞參數(shù)的方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12
python代碼實(shí)現(xiàn)邏輯回歸logistic原理
這篇文章主要介紹了python代碼實(shí)現(xiàn)邏輯回歸logistic原理,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08
ndarray的轉(zhuǎn)置(numpy.transpose()與A.T命令對(duì)比分析)
這篇文章主要介紹了ndarray的轉(zhuǎn)置(numpy.transpose()與A.T命令對(duì)比分析),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-02-02
pytorch __init__、forward與__call__的用法小結(jié)
這篇文章主要介紹了pytorch __init__、forward與__call__的用法小結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2021-02-02

