Pandas DataFrame at method with examples

Spread the love

The at method in Pandas is used to get a single value from a DataFrame based on the row index and column name. It is similar to loc method since they both supports label based indexing.

Syntax –[rowIndex, columnLabel]

Get a Value at a Specified row-column pair –

Let’s create a sample dataframe to illustrate it.

import pandas as pd

data = {'Name': ['Eleven','Mike','Lucas','Will','Max'],
       'Age': [18, 20, 20, 18, 19],
       'Sex': ['F', 'M', 'M', 'M', 'F'],
       'Marks': [99, 85, 82, 70, 80]}
df = pd.DataFrame(data)

Now, I can select a value using the at method. Let’s say you want to select Mike, for that you will write.[1, 'Name']

Set a Value at a specified row-column pair –

We can also set a value at a specified position using the at method. Let’s change the marks of Max from 80 to 90[4, 'Marks'] = 90

Rating: 1 out of 5.

Leave a Reply