I have a problem I want to groupby by and do some operation on a dataframe. The input dataframe is somethink like this:
我想基于unique_id进行分组,但是如果有两个观察,我需要在一个唯一ID中包含两行。 1个unique_ID中可以有任意数量的观察值
预期输出:
我曾尝试对它进行计数和其他一些列,以帮助groupby,但我没有为我工作。
df["Count_ob"] = df.groupby("Unique_ID")["IF_car_history"].sum()
寻求帮助。谢谢