Python pandas: Add a column to my dataframe that counts a variable Python pandas: Add a column to my dataframe that counts a variable pandas pandas

Python pandas: Add a column to my dataframe that counts a variable


Call transform this will return a Series aligned with the original df:

In [223]:df['count'] = df.groupby('group')['group'].transform('count')dfOut[223]:    org  group  count0  org1      1      21  org2      1      22  org3      2      13  org4      3      34  org5      3      35  org6      3      3