'How to resolve function Groupby, Max and Min problem (Pandas and Numpy)

I'm having trouble creating function to get highest and lowest close price value for a stock. pls help me to resolve the problem..

here is my code:

def get_high_low_close(df, symbol):
'''
Get highest and lowest close price of a stock.

Parameters
----------
df: Pandas DataFrame containing data from Problem 1's solution
symbol: stock symbol

Returns
-------
returns two values, highest and lowest close price of the stock.
'''
# YOUR CODE HERE

symbol = df.groupby('stock')['close']

highest_close = symbol.max()
lowest_close = symbol.min()

return highest_close, lowest_close

if call my function like this:

get_high_low_close(df, "AXP")

or

get_high_low_close(df, "AA")

then I get exactly same result for both of them like this:

(stock
 AA       17.92
 AXP      51.19
 BA       79.78
 BAC      15.25
 ...
 PG       67.36
 T        31.41
 TRV      63.43
 UTX      89.58
 VZ       38.47
 WMT      56.70
 XOM      87.98
 Name: close, dtype: float64,
 stock
 AA       14.72
 AXP      43.53
 BA       69.10
 BAC      10.52
 CAT      92.75
 ...
 PG       60.60
 T        27.49
 TRV      53.33
 UTX      79.08
 VZ       34.95
 WMT      51.52
 XOM      75.59
 Name: close, dtype: float64)

i got all the max and min value from all symbol from stock column. Meanwhile, what i want for my function is something like this:

in : get_high_low_close(df, "AA")

out: (17.92, 14.72)

Please help me to find the solution, Thank you..



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source