Search code examples
pythonpandascsvnonetype

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


I'm trying to create a csv file out of my Dataframe. I'm doing this with the .to_csv() method from pandas. But when I try to print the csv-file in the Terminal there is printed None. Maybe one of you know where the problem is

My code

Output in the Terminal


Solution

  • As the documentation states, to_csv return None if you supply the path_or_buf parameter (which you did, it's the first argument). So pandas act as it supposes, there is no problem.

    If you want to print the csv (and don't save it) you can:

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

    Not supplying `path_or_buf' parameter, this will return the csv formatted as a string