I'm just wondering how do I write a For loop in python to repetitively create variables as below:
file1 = '160321-PCU1.csv'
file2 = '160321-PCU2.csv'
file3 = '160321-PCU3.csv'
etc
file24 = '160321-PCU24.csv'
So I write a loop code below. But this gives me Syntax Error.
file = '160321-PCU'
for i in range(1,25):
'file'+str(i) = '160321-PCU'+str(i)+'.csv'
However this gives me error...
I'd also then to loop the following, where it does the following.... how do I compress the code and do loop properly?
#Read csv file and assign header
df1 = pd.read_csv(gdrive_url+file1+'.csv', sep=';', names=['Date','Time_Decimal','Parameter','Value'])
df2 = pd.read_csv(gdrive_url+file2+'.csv', sep=';', names=['Date','Time_Decimal','Parameter','Value'])
df3 = pd.read_csv(gdrive_url+file2+'.csv', sep=';', names=['Date','Time_Decimal','Parameter','Value'])
etc until it arrives at df24:
df24 = pd.read_csv(gdrive_url+file24+'.csv', sep=';', names=['Date','Time_Decimal','Parameter','Value'])
UPDATE! Hi all, I tried the following and it works, but then I'm still trying to figure out the next step which is to actually combine all dfs...
file = '160321-PCU'
for i in range(1,25):
filename = file+str(i)+'.csv'
df = pd.read_csv(gdrive_url+filename, sep=';', names=['Date','Time_Decimal','Parameter','Value'])
Next step is to concatenate df1, df2, ... df24?
Thank you all.