I am just starting to use user-defined functions, so this is probably not a very complex question, forgive me.
I have a few dataframes, which all have a column named 'interval_time' (for example) and I would like to rename this column 'Timestamp', and then make this renamed column into the index.
I know that I can do this manually with this;
df = df.rename(index=str, columns={'interval_time': 'Timestamp'})
df = df.set_index('Timestamp')
but now I would like to define a function called rename that does this for me. I have seen that this works;
def rename_col(data, col_in='tempus_interval_time', col_out='Timestamp'):
return data.rename(index=str, columns={col_in: col_out}, inplace=True)
but when I try to add the second function it does not seem to do anything, but if I define the second part as its own function and run it it does seem to work.
I am trying this
def rename_n_index(data, col_in='tempus_interval_time', col_out='Timestamp'):
return data.rename(index=str, columns={col_in: col_out}, inplace=True)
return data.set_index('Timestamp', inplace=True)
The dataframes that I am using have the following form;
df_scada
interval_time A ... X Y
0 2010-11-01 00:00:00 0.0 ... 396.36710 381.68860
1 2010-11-01 00:05:00 0.0 ... 392.97974 381.40634
2 2010-11-01 00:10:00 0.0 ... 390.15695 379.99493
3 2010-11-01 00:15:00 0.0 ... 389.02786 379.14810