简体   繁体   English

如何将 pandas dataframe output 保存到新创建的文件夹中的 ZCC8D68C551C4A9A6D5313EDZDE 文件中?

[英]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?如何将 pandas dataframe output 保存到 ZCC8D68C551C4A9A6D5313E0DZDE 新创建的项目文件夹中的 ZCC8D68C551C4A9A6D5313E0DZDE 文件夹中

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

folder = CSV_Script_Results # create this new folder at project root folder = CSV_Script_Results # 在项目根目录创建这个新文件夹

file = tweepy_spaces.csv # write this file inside ^ folder file = tweepy_spaces.csv # 将此文件写入 ^ 文件夹

The pandas doc isn't clear to me: Pandas Doc - to_csv我不清楚 pandas 文档: Pandas 文档 - 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...我希望解决方案涉及一行而不是导入操作系统、创建新目录等。不知道为什么会这样......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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