Reputation: 55
I need to import (read) a csv from a path. Each csv per day is saved as yyyymmdd_filename.csv in C:\
Using
pd.read_csv('C:/yyyymmdd_filename.csv')
I can import the file of a current date
However, I want to assign a variable date = today()
and run the file to import the csv.
So I imagine it would look something like this
pd.read_csv('C:/' + date + '*filename.csv')
Is this possible to do using pd.read_csv? if not what should I use
Upvotes: 0
Views: 258
Reputation: 426
Here is a small code :
from datetime import date
today=date.today()
print(today.strftime('%Y%m%d') #'20190321'
And for your case , to get the whole way to file:
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')
Upvotes: 1