Reputation: 77
I have some CSV files with its extension which keeps changes all the time.
I want to read these files automatically
df1=pd.read_csv('Active_count_'.csv)
df2=pd.read_csv('Deposit_'.csv)
df3=pd.read_csv('Game_Type_Wise_Net_Sell_'.csv)
df4=pd.read_csv('Total_Count_'.csv)
I want this in such a way that I want to keep after the underscore dynamic and load the CSV files. Is there a way I can achieve this?
Upvotes: 2
Views: 653
Reputation: 5144
This can be achieved outside Pandas using only standard Python functionality:
import glob
active_count_filename = glob.glob('Active_Count_*.csv')[0]
df1 = pd.read_csv(active_count_filename)
This assumes that there is exactly one Active_count_*
file - if none exists, it will throw an error, if more than one exists, one will be chosen randomly.
Upvotes: 1