Pandas.to_csv returns None 当打印出来而不是 csv 文件时

Pandas.to_csv returns None when printing out instead of a csv-file

我正在尝试从我的 Dataframe 中创建一个 csv 文件。我正在使用 pandas 中的 .to_csv() 方法执行此操作。但是当我尝试在终端中打印 csv 文件时,会打印 None。也许你们中有人知道问题出在哪里

documentation 所述,如果您提供 path_or_buf 参数(您提供的是第一个参数),则 to_csv return None。所以pandas如其所愿,没有问题。

如果您想打印 csv(但不保存),您可以:

print(forecast_array.to_csv(sep=';'))

不提供“path_or_buf”参数,这会将 return 格式为字符串的 csv