比方说:有一个数据框:
country Edition sports Athletes Medal Event_gender
Germany 1990 Aquatics HAJOS, Alfred gold X
Germany 1990 Aquatics HIRSCHMANN, Otto silver X
Germany 1990 Aquatics DRIVAS, Dimitrios silver M
US 2008 Athletics MALOKINIS, Ioannis gold M
US 2008 Athletics HAJOS, Alfred silver W
US 2009 Athletics CHASAPIS, Spiridon gold X
France 2010 Athletics CHOROPHAS, Efstathios gold X
France 2010 Athletics CHOROPHAS, Efstathios gold M
France 2010 golf HAJOS, Alfred silver M
France 2011 golf ANDREOU, Joannis silver W
Spain 2011 golf BURKE, Thomas gold W
我想找出多少个国家获得了金牌,其赛事性别等于'X'?
所以我试图解决它,但我被卡住了。我做到了:
df[df['Medal']== 'gold']['country'].nunique()
现在我已经获得了金牌的国家,但我在努力添加
df[df['Event_gender']== 'X']
根据以上逻辑获得最终结果。有人可以帮我吗?
答案 0 :(得分:2)
IIUC,是
df.loc[(df['Medal']=='gold') & (df['Event_gender']=='X'), 'country'].nunique()