简体   繁体   中英

How can I save pandas dataframe output to a CSV file in a newly created folder?

How can I save pandas dataframe output to a CSV file in a newly created folder at my project root?

spaces_df.to_csv(r'CSV_Script_Results/tweepy_spaces.csv', index=False)

folder = CSV_Script_Results # create this new folder at project root

file = tweepy_spaces.csv # write this file inside ^ folder

The pandas doc isn't clear to me: Pandas Doc - to_csv

I found an answer:

import os
os.mkdir('CSV_Script_Results')
spaces_df.to_csv(r'CSV_Script_Results/tweepy_spaces.csv', index=False)

I was hoping the solution involved one line instead of importing os, creating a new directory, etc. Not sure why that's the way it is...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM