[英]Importing csv to python with Variable Name
我需要從路徑導入(讀取)csv。 每天每個csv均另存為yyyymmdd_filename.csv在C:\\中
使用pd.read_csv('C:/yyyymmdd_filename.csv')
我可以導入當前日期的文件
但是,我想分配一個變量date = today()
並運行文件以導入csv。
所以我想它看起來像這樣pd.read_csv('C:/' + date + '*filename.csv')
使用pd.read_csv可以做到嗎? 如果不是,我應該用什么
這是一個小代碼:
from datetime import date
today=date.today()
print(today.strftime('%Y%m%d') #'20190321'
對於您的情況,獲得完整的歸檔方式:
print('C:/{}_filename.csv'.format(today.strftime('%Y%m%d')))
print(f'C:/{today.strftime("%Y%m%d")}_filename.csv') #don't use the same quote inside and outside or it won't work, of course.
print('C:/'+today.strftime('%Y%m%d')+'_filename.csv')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.