2016-11-10 2 views
0
# Name Type 1 Type 2 Total HP Attack Defense 
1 Bulbasaur Grass Poison 318  45 49  65  
2 Ivysaur  Grass Poison 405  60 62  80  
3 Venusaur Grass Poison 525  80 82  100  
4 Charmander Fire NaN  309  39 52  60  
5 Charmeleon Fire NaN  405  58 64  80 

위와 같은 데이터 프레임이 있습니다. '유형 1'에서 '잔디'유형 포케몬의 수를 계산해야합니다. 어떻게하면됩니까?데이터 프레임의 한 열에있는 유사한 값의 수를 어떻게 계산합니까?

답변

0

IIUC 당신은 value_counts 필요

df = df['Type 1'].value_counts() 
print (df) 
Grass 3 
Fire  2 
Name: Type 1, dtype: int64 

또는 groupbysize를 집계로 :

df = df.groupby(['Type 1']).size() 
print (df) 
Type 1 
Fire  2 
Grass 3 
dtype: int64 
관련 문제