ikel
ikel

Reputation: 1978

how to refer to a cell in dataframe

I have run the following code

from pandas_datareader.data import Options
aapl = Options('aapl', 'yahoo')
data = aapl.get_all_data()
data.head()

and I got following out put enter image description here

let's say under 'Vol' there is one cell with value '13', how do i access that value in this dataframe? at first, i have tried data['Vol'] to get 'Vol' column but it failed

df=data.loc[(slice(None), slice(None), 'put'),'Vol':'Vol'] 
df

enter image description here

it seems i cannot get only 'Vol' column for some reason

Upvotes: 1

Views: 1857

Answers (1)

jezrael
jezrael

Reputation: 862691

I think you need boolean indexing with loc - it return all values with 13 in column Vol:

mask = data['Vol'] == 13
vals = data.loc[mask, 'Vol']

For first 13 select by position by iloc or iat:

first = vals.iloc[0]
first = vals.iat[0]

Upvotes: 1

Related Questions