0

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

tp_1290
  • 55
  • 1
  • 1
  • 5
  • 1
    Check out there : https://stackoverflow.com/questions/311627/how-to-print-a-date-in-a-regular-format – olinox14 Mar 21 '19 at 16:38

1 Answers1

1

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')
HappyCloudNinja
  • 386
  • 1
  • 2
  • 13
  • thanks, but how can i also implement the today while importing my csv? – tp_1290 Mar 21 '19 at 17:16
  • pd.read_csv('C:/{}_filename.csv'.format(today.strftime('%Y%m%d'))) or pd.read_csv(f'C:/{today.strftime('%Y%m%d')}_filename.csv') or pd.read_csv('C:/'+today.strftime('%Y%m%d')+'_filename.csv') – HappyCloudNinja Mar 22 '19 at 06:50