Chadee Fouad
Chadee Fouad

Reputation: 2938

Pandas get cell value by row NUMBER (NOT row index) and column NAME

data = [['tom', 10], ['nick', 15], ['juli', 14]] 
df = pd.DataFrame(data, columns = ['Name', 'Age'], index = [7,3,9])
display(df)
df.iat[0,0]

enter image description here

I'd like to return the Age in first row (basically something like df.iat[0,'Age']. Expected result = 10

Thanks for your help!

Upvotes: 5

Views: 7324

Answers (2)

Randy Maldonado
Randy Maldonado

Reputation: 372

df['Age'].iloc[0] works too, similar to what Chris had answered.

Upvotes: 7

Chris
Chris

Reputation: 29732

Use iloc and Index.get_loc:

df.iloc[0, df.columns.get_loc("Age")]

Output:

10

Upvotes: 4

Related Questions