python - How do i count the number of similar values in a column in dataframe? -


    #   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   

i have dataframe above. need calculate number of 'grass' type pokemons 'type 1'. how do that?

iiuc need value_counts:

df = df['type 1'].value_counts() print (df) grass    3 fire     2 name: type 1, dtype: int64 

or groupby aggregating size:

df = df.groupby(['type 1']).size() print (df) type 1 fire     2 grass    3 dtype: int64 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -