Calculating mean, std.dev and variance and creating a new data frame from these calculations in python

前端 未结 3 789
一个人的身影
一个人的身影 2020-12-30 17:17

My dataframe

date   Stk A     Stk B  Stk C   Stk D
01.01   0.03    0.0102  0.034   0.083232
02.02   0.05    0.017   0.0578  0.13872
03.03   0.04    0.0136          


        
相关标签:
3条回答
  • 2020-12-30 17:19

    Using pandas library in python

    import pandas as pd
    stats=pd.DataFrame()
    stats["mean"]=data.mean()
    stats["Std.Dev"]=data.std()
    stats["Var"]=data.var()
    

    And then transpose it like

    stats.T
    
    0 讨论(0)
  • 2020-12-30 17:27

    You can do something like this:

    option 1

    pd.DataFrame([df.mean(), df.std(), df.var()], index=['Mean', 'Std. dev', 'Variance'])
    

    or something like this:

    option 2

    df2 = df.describe().loc[['mean', 'std']]
    df2.loc['variance'] = df2.loc['std']**2
    
    0 讨论(0)
  • 2020-12-30 17:43

    df.describe() will do the trick.

    my_df.describe()
    
                    Age
    count  37471.000000  
    mean      43.047317      
    std       20.676562      
    min        1.000000     
    25%       28.000000     
    50%       43.000000     
    75%       59.000000 
    max      117.000000
    
    0 讨论(0)
提交回复
热议问题