简体   繁体   English

如何使用 to_csv function 将用户输入设置为 CSV 文件名?

[英]How set user input as CSV file name using to_csv function?

SO I want to extract stocks date from the NSE module using get_history by allowing which company to choose and want to convert the data collected into CSV file using company name as CSV file name.所以我想使用 get_history 从 NSE 模块中提取股票日期,方法是允许选择哪家公司并希望将收集到的数据转换为 CSV 文件,使用公司名称作为 CSV 文件名。

X = input('Symbol of the Company:')
X = get_history(symbol=X, start = date(2020,12,1), end = date(2021,2,27))
X = DataFrame(X)
X.to_csv(X.csv)

I tried to use above to_csv but it is showing an error if I put them in quote the file is saved as X.我尝试在 to_csv 上面使用,但如果我将它们放在引号中,则会显示错误,文件保存为 X。

The solution is to keep ".csv" as string, but not X:解决方案是将“.csv”保留为字符串,而不是 X:

X = input('Symbol of the Company:')
X = get_history(symbol=X, start = date(2020,12,1), end = date(2021,2,27))
X = DataFrame(X)
X.to_csv(X + ".csv")

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

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