pythondataframeloopstransposein-place

Transpose a dataframe inplace into a for loop (python-pandas)


I have a list of dataframes. All the dataframes have 75 columns and variable number of rows (between 18 to 1000). The column names are dates, I will use these dates to plot time series. There are ~50 dataframes in the list. I want to tranpose all the dataframes and I want to use a for loop. I am also doing some other editions to the dataframes inside the loop (e.g., dates to datetime format)

I know that df.T allows to transpose a dataframe, however when I do for df in dfs: df = df. T it does not work, it does not save inplace. I am traying to find a way to do it inplace but I have not find any solution. I also tried for df in dfs: df.tranpose() and it does not work.


Solution

  • Maybe try something like:

    for i in range(len(dfs)):
        dfs[i] = dfs[i].T
    

    This should write the transposed dataframe back into the list.