[英]How to create a column based on the min and max of another dataframe
[英]Creating a new Min() and Max() column based another dataframe
我正在嘗試根據現有數據幀的 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'})
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.