熊猫to_csv()–将DataFrame转换为CSV

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
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值