Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read a csv file with its name changing daily

I am trying to read a csv file in Pandas. I am automating the script to daily read the data from csv and execute. Daily a new csv is added in the folder where i have the csv files. Newly added csv file have the same name format except the date part in it changes daily and month part change monthly. Year would change yearly. How can i automate to read the csv files daily with its name changing continuously?

Example: If the name for yesterday`s file is:

Name_29Mar2020_data_by_company.csv

Tomorrow`s file will be:

Name_30Mar2020_data_by_company.csv
like image 318
Sara Avatar asked Nov 28 '25 23:11

Sara


1 Answers

You can use the datetime module:

import pandas as pd
from datetime import datetime

fname = datetime.today().strftime('Name_%d%b%Y_data_by_company.csv')
df = pd.read_csv(fname)
like image 142
Bruno Mello Avatar answered Nov 30 '25 16:11

Bruno Mello



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!