2 回答
TA贡献1793条经验 获得超6个赞
尝试
x = df.groupby(['brand'])['result'].value_counts(normalize=True)
样本数据输出
>>> y = x.loc[(x.index.get_level_values(1) == 'negative')]
>>> y[y>0.2]
airline airline_sentiment
American negative 0.710402
Delta negative 0.429793
Southwest negative 0.490083
US Airways negative 0.776862
United negative 0.688906
Virgin America negative 0.359127
Name: airline_sentiment, dtype: float64
>>> y[y>0.2].index.get_level_values(0)
Index(['American', 'Delta', 'Southwest', 'US Airways', 'United',
'Virgin America'],
dtype='object', name='airline')
TA贡献1821条经验 获得超4个赞
添加到@Vishnudev 的答案,使用:
print(df[df.groupby(['brand'])['result'].value_counts(normalize=True).ge(0.5).tolist()])
输出:
brand result number
3 Estee Lauder negative 7
4 Estee Lauder positive 23
添加回答
举报