Python Forum

Full Version: Final df to csv
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm having trouble saving the data-frame as a CSV.

>>> print(len(df))
221
>>> final_df = df.sort_values('popularity', ascending=False).drop_duplicates('name').sort_index()
>>> print(len(final_df))
116
>>> 
>>> final_df.to_csv("{a file location to store your csv}")
>>> final_df.to_csv("Desktop")
>>> final_df.to_csv("/Users/Pablo/Desktop/SP")
Traceback (most recent call last):
  File "<pyshell#136>", line 1, in <module>
    final_df.to_csv("/Users/Pablo/Desktop/SP")
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/generic.py", line 3020, in to_csv
    formatter.save()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/io/formats/csvs.py", line 157, in save
    compression=self.compression)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/io/common.py", line 424, in _get_handle
    f = open(path_or_buf, mode, encoding=encoding, newline="")
IsADirectoryError: [Errno 21] Is a directory: '/Users/Pablo/Desktop/SP'
Try adding a filename
final_df.to_csv("/Users/Pablo/Desktop/SP/filename_here.csv")