时间:2021-05-22
用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='.')Write DataFrame to a comma-separated values (csv) filepath_or_buf : string or file handle, default NoneFile path or object, if None is provided the result is returned as a string.sep : character, default ‘,'Field delimiter for the output file.na_rep : string, default ‘'Missing data representationfloat_format : string, default NoneFormat string for floating point numberscolumns : sequence, optionalColumns to writeheader : boolean or list of string, default TrueWrite out the column names. If a list of strings is given it is assumed to be aliases for the column namesindex : boolean, default TrueWrite row names (index)index_label : string or sequence, or False, default NoneColumn label for index column(s) if desired. If None is given, and header and index are True, then the index names are used. A sequence should be given if the DataFrame uses MultiIndex. If False do not print fields for index names. Use index_label=False for easier importing in Rmode : strPython write mode, default ‘w'encoding : string, optionalA string representing the encoding to use in the output file, defaults to ‘ascii' on Python 2 and ‘utf-8' on Python 3.compression : string, optionala string representing the compression to use in the output file, allowed values are ‘gzip', ‘bz2', ‘xz', only used when the first argument is a filenameline_terminator : string, default '\n'The newline character or character sequence to use in the output filequoting : optional constant from csv moduledefaults to csv.QUOTE_MINIMAL. If you have set a float_format then floats are converted to strings and thus csv.QUOTE_NONNUMERIC will treat them as non-numericquotechar : string (length 1), default ‘”'character used to quote fieldsdoublequote : boolean, default TrueControl quoting of quotechar inside a fieldescapechar : string (length 1), default Nonecharacter used to escape sep and quotechar when appropriatechunksize : int or Nonerows to write at a timetupleize_cols : boolean, default FalseDeprecated since version 0.21.0: This argument will be removed and will always write each row of the multi-index as a separate row in the CSV file.Write MultiIndex columns as a list of tuples (if True) or in the new, expanded format, where each MultiIndex column is a row in the CSV (if False).date_format : string, default NoneFormat string for datetime objectsdecimal: string, default ‘.'Character recognized as decimal separator. E.g. use ‘,' for European data以上这篇python的pandas工具包,保存.csv文件时不要表头的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
python判断文件和字符串编码类型可以用chardet工具包,可以识别大多数的编码类型。但是前几天在读取一个Windows记事本保存的txt文件时,GBK却被
1、问题在使用Python中pandas读取csv文件时,由于文件编码格式出现以下问题:Traceback(mostrecentcalllast):File"p
第一:pandas.read_csv读取本地csv文件为数据框形式data=pd.read_csv('G:\data_operation\python_book
项目实现知识点:Pandas库及pyecharts库Pandas:数据分析和处理工具。pd.read_csv():读取csv文件。pyecharts:绘图库,提
下载刷机工具包 •刷机工具包 刷机工具包 •将下载所得的刷机工具包解压,解压后有三个文件夹,如下图 安装线刷驱动 •