【发布时间】:2021-12-05 04:20:20
【问题描述】:
【问题讨论】:
标签: python-3.x pandas
【问题讨论】:
标签: python-3.x pandas
尝试 groupby、agg 和 pd.join
newdf=(df.set_index('stayid')#Set stayid to allow joining of the aggregated to the main df
.join(# This joins the ggregated df to main df
df.groupby('stayid')['temp'].agg([min,max])# Compute the min and max temperature and put them into a summarised df
).rename(columns={'min':'min_temp', 'max':'max_temp'}))#rename the min and max columns)
【讨论】: