现有Dataframe:
PushedDate ID_number
amin amax
index
7874 2022-02-18 2022-02-22 7874
4979 2021-10-06 2021-10-11 4979我正在寻找dataframe,在这里我将使用amin和amax作为单独的列:
PushedDate_min PushedDate_max ID_number
index
7874 2022-02-18 2022-02-22 7874
4979 2021-10-06 2021-10-11 4979使用以下代码获得了现有的数据:
aa = df.groupby(['ID_number']).agg({'PushedDate': [np.min, np.max]})
aa[aa.index.name] = aa.index
aa.index.names = ['index'] # renaming the index发布于 2022-08-12 13:58:41
相反,您可以这样做:
aa = df.groupby(['ID_number']).agg({'PushedDate': [np.min, np.max]})
aa.columns = [f'{x}_{y}' for x,y in aa.columns]
aa = aa.reset_index()https://stackoverflow.com/questions/73335212
复制相似问题