Issue
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.
'''
I am trying to create a user defined function which will display max and min price for selected symbol.
I have the following code but it will only display the max and min for the close column from data frame. As per the lecture I am supposed to incorporate boolean mask but i am not sure how.
def get_high_low_close(df, symbol):
symbol = df[df.stock == "AA"]
highest_close = df['close'].max()
lowest_close = df['close'].min()
return highest_close, lowest_close
Solution
Not sure what you want exactly, I'm guessing:
def get_high_low_close(df, symbol):
mask = df['stock'] == symbol
highest_close = df.loc[mask, 'close'].max()
lowest_close = df.loc[mask, 'close'].min()
return highest_close, lowest_close
See boolean indexing.
Answered By - mozway
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.