Pandas DataFrame to_csv() function converts DataFrame into CSV data. We can pass a file object to write the CSV data into a file. Otherwise, the CSV data is returned in the string format.
Pandas DataFrame的to_csv()函数将DataFrame转换为CSV数据。 我们可以传递文件对象以将CSV数据写入文件。 否则,将以字符串格式返回CSV数据。
Pandas DataFrame to_csv()语法 (Pandas DataFrame to_csv() Syntax)
The syntax of DataFrame to_csv() function is:
DataFrame to_csv()函数的语法为:
def to_csv(
self,
path_or_buf=None,
sep=",",
na_rep="",
float_format=None,
columns=None,
header=True,
index=True,
index_label=None,
mode="w",
encoding=None,
compression="infer",
quoting=None,
quotechar='"',
line_terminator=None,
chunksize=None,
date_format=None,
doublequote=True,
escapechar=None,
decimal=".",
)
Some of the important parameters are:
一些重要的参数是:
- path_or_buf: the file object to write the CSV data. If this argument is not provided, the CSV data is returned as a string. path_or_buf :用于写入CSV数据的文件对象。 如果未提供此参数,则CSV数据作为字符串返回。
- sep: the delimiter for the CSV data. It should be a string of length 1, the default is a comma. sep :CSV数据的分隔符。 它应该是长度为1的字符串,默认为逗号。
- na_rep: string representing null or missing values, default is empty string. na_rep :表示空值或缺少值的字符串,默认为空字符串。
- columns: a sequence to s