从pandas v15.0开始,当数据框具有混合列类型时,使用参数
DataFrame.describe(include = all)获取所有列的摘要.默认行为仅提供数值列的摘要.
例:
In[1]:
df = pd.DataFrame({'$a':['a', 'b', 'c', 'd', 'a'], '$b': np.arange(5)})
df.describe(include = 'all')
Out[1]:
$a $b
count 5 5.000000
unique 4 NaN
top a NaN
freq 2 NaN
mean NaN 2.000000
std NaN 1.581139
min NaN 0.000000
25% NaN 1.000000
50% NaN 2.000000
75% NaN 3.000000
max NaN 4.000000
数字列将具有NaN用于与对象(字符串)相关的摘要统计信息,反之亦然.
仅汇总数字或对象列
>调用describe()在数字列上使用describe(include = [np.number])
>使用describe(include = [‘O’])调用对象(字符串)上的describe().
In[2]:
df.describe(include = [np.number])
Out[3]:
$b
count 5.000000
mean 2.000000
std 1.581139
min 0.000000
25% 1.000000
50% 2.000000
75% 3.000000
max 4.000000
In[3]:
df.describe(include = ['O'])
Out[3]:
$a
count 5
unique 4
top a
freq 2
从Pandas v15.0开始,DataFrame.describe()方法可以处理混合类型的列,包括数值和非数值类型。默认情况下,它只提供数值列的统计摘要。要包含所有列,可以设置include='all'。例如,对于包含字符串和数字的DataFrame,describe()会为每种类型列分别提供摘要信息。数字列在对象列中会有NaN值,反之亦然。可以使用describe(include=[np.number])仅对数字列进行摘要,或者使用describe(include=['O'])仅对对象列进行摘要。
1784

被折叠的 条评论
为什么被折叠?



