Apply different functions to different columns with a singe pandas groupby command
问题 My data is stored in df . I have multiple users per group . I want to group df by group and apply different functions to different columns. The twist is that I would like to assign custom names to the new columns during this process. np.random.seed(123) df = pd.DataFrame({"user":range(4),"group":[1,1,2,2],"crop":["2018-01-01","2018-01-01","2018-03-01","2018-03-01"], "score":np.random.randint(400,1000,4)}) df["crop"] = pd.to_datetime(df["crop"]) print(df) user group crop score 0 0 1 2018-01-01