-1

Im relatively new to python so forgive me if this is a dumb question, but i currently have a dataframe that looks like this:

                close
date                 
2020-07-24  69.400002
2020-07-23  59.570000
2020-07-22  61.790000

this was pulled using this code:

stockprices = requests.get(f"https://financialmodelingprep.com/api/v3/historical-price-full/{stock}?serietype=line&apikey=992f4ace89c00105ff6c15b225372d70")
stockprices = stockprices.json()

stockprices = stockprices['historical'][:60]



stockprices = pd.DataFrame.from_dict(stockprices)
stockprices = stockprices.set_index('date')

My question is how can i get a specific price for a specific column, like for example "59.57" from date "2020-07-23"

Ignition K6
  • 147
  • 1
  • 1
  • 14

2 Answers2

2

For this, you can give in the stockprices.at[] property.

So for example, if you wanted to get the stock price on July 23rd, you could do the following:

stockprices.at['2020-07-23', 'close']

Similar to loc, in that both provide label-based lookups. Use at if you only need to get or set a single value in a DataFrame or Series.

Warning: Note that contrary to usual python slices, both the start and the stop are included.

If you want to get access a single value for a row/column pair by integer position, use the stockprices.iat[] property.

0
import pandas as pd
Dictionary = {"Date" : ["2020-07-22","2020-07-23","2020-07-24"],
"Close" : ["61.790000","59.570000","69.400002"],"Price" : ["22","23","24"]}
df = pd.DataFrame(Dictionary)
filter_val = df['Date'] == "2020-07-23"
df.where(filter_val)```
Umair Mubeen
  • 823
  • 4
  • 22