【问题标题】:How to count frequency of a value in a column of a data frame based on another column?How to count frequency of a value in a column of a data frame based on another column?
【发布时间】:2022-12-02 03:10:59
【问题描述】:

I have dataframe with different traffic signs in different neighborhoods (both are columns). I want to count the quantity of each sign type in each neighborhood.

i could create a query for each neighborhood and the count the value of each sign type like that but there are too many neighborhoods for that to be practical.

【问题讨论】:

    标签: python pandas dataframe


    【解决方案1】:

    You can group by the neighbourhood and sign type and do a size to have the count of each sign type in each neighbourhood.

    Sample code

    df.groupby(["neighbourhood", "sign_type"]).size()
    

    【讨论】:

      猜你喜欢
      • 2022-12-02
      • 2022-12-02
      • 2022-12-01
      • 2022-12-02
      • 2022-12-02
      • 2022-12-02
      • 2022-12-26
      • 2022-12-01
      • 2022-12-02
      相关资源
      最近更新 更多