python

Get a value from DataFrame row using index and column name in pandas

If you want to get the single value from a row using its index and column name you can use at() method of pandas DataFrame.

import pandas as pd

df = pd.DataFrame([[0, 2, 3], [0, 4, 1], [10, 20, 30]],
                  index=[1, 2, 3], columns=['A', 'B', 'C'])

#index - 3, column_name - 'C'
value = df.at[3, 'C']
print(value) # prints - 30

#this can also written as
value = df.loc[3].at['C']
print( value ) # prints - 30
Was this helpful?