![](/img/trans.png)
[英]How to calculate the mean of “n” outputs which I got after using for loop and assign it to a variable?
[英]How to assign to a variable the outputs of the method “describe”?
25% 和 50% 是分位数,因此您可以简单地使用 pandas quantile
function 来获取这些值。
对于您在describe
output 中看到的所有信息,您可以使用pandas.DataFrame
中的函数,例如:
count -> pandas.DataFrame.count
mean -> pandas.DataFrame.mean
std -> pandas.DataFrame.std
min -> pandas.DataFrame.min
25%, 50%, 75% or any other quantile -> pandas.DataFrame.quantile
max -> pandas.DataFrame.max
pd.DataFrame.describe
返回一个 dataframe,您可以使用 loc 访问 dataframe 的每个单元格,也可以直接计算 stat。
import pandas as pd
from seaborn import load_dataset
df_tips = load_dataset('tips')
print(df_tips.describe())
Output:
total_bill tip size
count 244.000000 244.000000 244.000000
mean 19.785943 2.998279 2.569672
std 8.902412 1.383638 0.951100
min 3.070000 1.000000 1.000000
25% 13.347500 2.000000 2.000000
50% 17.795000 2.900000 2.000000
75% 24.127500 3.562500 3.000000
max 50.810000 10.000000 6.000000
获得 25%:
df_tips.describe().loc['25%', 'total_bill']
#or
df_tips['total_bill'].quantile(.25)
Output:
13.3475
获得 50%:
df_tips.describe().loc['50%', 'total_bill']
#or
df_tips['total_bill'].quantile(.50)
Output:
17.795
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.