pandasdataframemeantranspose

Mean value of a Dataframe comes out transposed


I am iterating over serval files and for each file I get a data frame.

enter image description here

I then calculate mean for each data frame using following.

BinA_Data.mean(axis=0,skipna=True, numeric_only=True))

But the results I get is a series where indexes are the column names like

enter image description here

But actually I want to have mean value show up with column names "as is" like

enter image description here

Later on I want to concatenate the mean calculated for each file to show something like this.

enter image description here

I tried using transpose() but still the mean always shows with column names as index and I loose the column name which I want to preserve. Any suggestions?

Above is a sample data actual mean not match with the mean values shown.


Solution

  • Example Code

    You should not provide samples of your examples as images, but rather provide a minimal and reproducible example.

    Since the result generated by your code(BinA_Data.mean(axis=0,skipna=True, numeric_only=True)) is a series, we will generate a simple series s as a sample

    import pandas as pd
    s = pd.Series([1, 2, 3], index=['A', 'B', 'C'])
    

    s

    A    1
    B    2
    C    3
    dtype: int64
    

    Code

    Since the series is one-dimensional, it cannot be transposed. Convert to a data frame and try transpose.

    out = s.to_frame().T
    

    out

        A   B   C
    0   1   2   3