Creating a new Min() and Max() column based another dataframe

Viewed 57

I'm trying to create two columns in a new dataframe base on the Min and the Min from an existing dataframe. When groupby is used, it is giving min and max NAN values

df.groupby('street').min()['sold_price']
df.groupby('street').max()['sold_price']

sample from existing dataframe.

street_name sold_price
A            100,000
A            200,100
B            50,000
B            100,000

new dataframe should be

street_name   min        max
A             100,000    200,000
B             50,000     100,000
1 Answers

It should be

(df.groupby("street_name", as_index=False)
    ["sold_price"].agg(["min","max"])
)

Update: for rename:

(df.groupby("street_name", as_index=False)
    ["sold_price"].agg({'low':'min', 'high':'max'})
)
Related