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

1

1 Answer 1

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')
Sign up to request clarification or add additional context in comments.

2 Comments

thanks, but how can i also implement the today while importing my csv?
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')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.