我正在尝试基于Min和现有数据框中的Min在新数据框中创建两列。使用groupby时,它将给出最小和最大NAN值
df.groupby('street').min()['sold_price']
df.groupby('street').max()['sold_price']
现有数据帧中的样本。
street_name sold_price
A 100,000
A 200,100
B 50,000
B 100,000
新数据框应为
street_name min max
A 100,000 200,000
B 50,000 100,000
它应该是
(df.groupby("street_name", as_index=False)
["sold_price"].agg(["min","max"])
)
更新:重命名:
(df.groupby("street_name", as_index=False)
["sold_price"].agg({'low':'min', 'high':'max'})
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句