python将pandas datarame保存为txt文件的实例
CSVmeansCommaSeparatedValues.Itisplaintext(ansi).
TheCSV("CommaSeparatedValue")fileformatisoftenusedtoexchangedatabetweendisparateapplications.Thefileformat,asitisusedinMicrosoftExcel,hasbecomeapseudostandardthroughouttheindustry,evenamongnon-Microsoftplatforms.
TXTisnotreallyafileformat,anditcouldmeanmultiplethingsindifferentcontexts.GenerallyyouexporttablesineitherCSV(commaseparatedvalues)orTSV(tabseparatedvalues).Whichyoushouldchoosedependsmainlyonyourdata:ifyourdatahascommasinitbutnottabs,youshouldgoforTSV.
#-*-coding:UTF-8-*-
importsys
importjson
reload(sys)
sys.setdefaultencoding('utf-8')
importpandasaspd
importnumpyasnp
#读取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将pandasdatarame保存为txt文件的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。