I have the followings pandas dataframes
phreatic_level_l2n1_28w_df.head()
Fecha Hora PORVL2N1 # PORVLxNx column change their name in each data frame
0 2012-01-12 01:37:47 0.65
1 2012-01-12 02:37:45 0.65
2 2012-01-12 03:37:50 0.64
3 2012-01-12 04:37:44 0.63
4 2012-01-12 05:37:45 0.61
And so, successively until have 25 data frames of type phreatic_level_l24n2_28w_df
.
.
.
phreatic_level_l24n2_28w_df.head()
Fecha Hora PORVL24N2 # PORVLxNx column change their name in each data frame
0 2018-01-12 01:07:28 1.31
1 2018-01-12 02:07:28 1.31
2 2018-01-12 03:07:29 1.31
3 2018-01-12 04:07:27 1.31
4 2018-01-12 05:07:27 1.31
My objective is to iterate each record ( all data frames) to apply the following process
for i in range(1,25):
if (i==2):
# We turn to datetime the Fecha column values
phreatic_level_l{}n{}_28w_df['Fecha'].format(i,i-1) = pd.to_datetime(phreatic_level_l'{}'n'{}'_28w_df['Fecha'].format(i,i-1))
.
.
# And so, successively until have 25 data frames
But I have the following error, due to format() function, it should be applied on strings only and not to any variable name.
File "<ipython-input-72-1f6ad7811399>", line 5
phreatic_level_l{}n{}_28w_df['Fecha'].format(i,i-1) = pd.to_datetime(phreatic_level_l'{}'n'{}'_28w_df['Fecha'].format(i,i-1))
^
SyntaxError: invalid syntax
globals()orvars(), but what you should really do is just make a list of the 25 DFs and iterate over that