pandas dataframe to_csv多一列的问题以及to_csv参数详解

df.to_csv("test.csv",encoding='utf-8',index=False)

在后面加上index = False即可

Write DataFrame to a comma-separated values (csv) file

Parameters:

path_or_buf : string or file handle, default None

File 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 representation

缺失数据表示

float_format : string, default None

Format string for floating point numbers

浮点数的转为字符串

columns : sequence, optional

Columns to write

要写的列

header : boolean or list of string, default True

Write out the column names. If a list of strings is given it is assumed to be aliases for the column names

写出列名。如果给出了字符串列表,则假定它是列名的别名

index : boolean, default True

Write row names (index)

写行名(索引)

index_label : string or sequence, or False, default None

Column label for index column(s) if desired. If None is given, and header and indexare 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 R

索引列的列标签(如果需要)。如果给出None,并且header和index为True,则使用索引名称。如果DataFrame使用MultiIndex,则应该给出一个序列。如果为False,则不输出索引名称的字段。使用index_label = False可以更轻松地导入R

mode : str

Python write mode, default ‘w’

写的模式:str

encoding : string, optional

A string representing the encoding to use in the output file, defaults to ‘ascii’ on Python 2 and ‘utf-8’ on Python 3.

表示要在输出文件中使用的编码的字符串,默认为Python 2上的“ascii”和Python 3上的“utf-8”。

compression : string, optional

A string representing the compression to use in the output file. Allowed values are ‘gzip’, ‘bz2’, ‘zip’, ‘xz’. This input is only used when the first argument is a filename.

表示要在输出文件中使用的压缩的字符串。允许的值为'gzip','bz2','zip','xz'。仅当第一个参数是文件名时才使用此输入

line_terminator : string, default '\n'

The newline character or character sequence to use in the output file

要在输出文件中使用的换行符或字符序列

quoting : optional constant from csv module

defaults 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-numeric

quotechar : string (length 1), default ‘”’

character used to quote fields

doublequote : boolean, default True

Control quoting of quotechar inside a field

escapechar : string (length 1), default None

character used to escape sep and quotechar when appropriate

chunksize : int or None

rows to write at a time

tupleize_cols : boolean, default False

Deprecated 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 None

Format string for datetime objects

decimal: string, default ‘.’

Character recognized as decimal separator. E.g. use ‘,’ for European data

猜你喜欢

转载自blog.csdn.net/weixin_38987362/article/details/81327011