python的pandas工具包,保存.csv文件时不要表头的实例
用pandas处理.csv文件时,有时我们希望保存的.csv文件没有表头,于是我去看了DataFrame.to_csv的document。
发现只需要再添加header=None这个参数就行了(默认是True),
下面贴上document:
DataFrame.to_csv(path_or_buf=None,sep=',',na_rep='',float_format=None,columns=None,header=True,index=True,index_label=None,mode='w',encoding=None,compression=None,quoting=None,quotechar='"',line_terminator='\n',chunksize=None,tupleize_cols=None,date_format=None,doublequote=True,escapechar=None,decimal='.') WriteDataFrametoacomma-separatedvalues(csv)file
path_or_buf:stringorfilehandle,defaultNone Filepathorobject,ifNoneisprovidedtheresultisreturnedasastring. sep:character,default‘,' Fielddelimiterfortheoutputfile. na_rep:string,default‘' Missingdatarepresentation float_format:string,defaultNone Formatstringforfloatingpointnumbers columns:sequence,optional Columnstowrite header:booleanorlistofstring,defaultTrue Writeoutthecolumnnames.Ifalistofstringsisgivenitisassumedtobealiasesforthecolumnnames index:boolean,defaultTrue Writerownames(index) index_label:stringorsequence,orFalse,defaultNone Columnlabelforindexcolumn(s)ifdesired.IfNoneisgiven,andheaderandindexareTrue,thentheindexnamesareused.AsequenceshouldbegiveniftheDataFrameusesMultiIndex.IfFalsedonotprintfieldsforindexnames.Useindex_label=FalseforeasierimportinginR mode:str Pythonwritemode,default‘w' encoding:string,optional Astringrepresentingtheencodingtouseintheoutputfile,defaultsto‘ascii'onPython2and‘utf-8'onPython3. compression:string,optional astringrepresentingthecompressiontouseintheoutputfile,allowedvaluesare‘gzip',‘bz2',‘xz',onlyusedwhenthefirstargumentisafilename line_terminator:string,default'\n' Thenewlinecharacterorcharactersequencetouseintheoutputfile quoting:optionalconstantfromcsvmodule defaultstocsv.QUOTE_MINIMAL.Ifyouhavesetafloat_formatthenfloatsareconvertedtostringsandthuscsv.QUOTE_NONNUMERICwilltreatthemasnon-numeric quotechar:string(length1),default‘”' characterusedtoquotefields doublequote:boolean,defaultTrue Controlquotingofquotecharinsideafield escapechar:string(length1),defaultNone characterusedtoescapesepandquotecharwhenappropriate chunksize:intorNone rowstowriteatatime tupleize_cols:boolean,defaultFalse Deprecatedsinceversion0.21.0:Thisargumentwillberemovedandwillalwayswriteeachrowofthemulti-indexasaseparaterowintheCSVfile. WriteMultiIndexcolumnsasalistoftuples(ifTrue)orinthenew,expandedformat,whereeachMultiIndexcolumnisarowintheCSV(ifFalse). date_format:string,defaultNone Formatstringfordatetimeobjects decimal:string,default‘.' Characterrecognizedasdecimalseparator.E.g.use‘,'forEuropeandata
以上这篇python的pandas工具包,保存.csv文件时不要表头的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语