Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Final df to csv
#1
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'
Reply
#2
Try adding a filename
final_df.to_csv("/Users/Pablo/Desktop/SP/filename_here.csv")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  What is the best approach to training a final model after cross validation? amjass12 0 1,864 Jul-21-2021, 10:15 AM
Last Post: amjass12

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020