Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
pandas

What is the at method in pandas?

Hassaan Waqar

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The at method in pandas is used to get a single value from a dataframe based on the row index and column name. The at method needs two parameters: the row index and column name.

It then returns the value of the specified position.

The at method is similar to the loc method since it supports label-based indexing.

The illustration below shows how the at method works in pandas:

Syntax

The syntax of the at method is as follows:

Dataframe.at[rowIndex, columnLabel]

Parameters

The at method takes a rowIndex and a columnLabel.

Return value

The at method returns the value at the corresponding position.

Errors

The key error is raised if the parameters passed as row index and column labels are out of bound or not present in the dataframe.

Example

The code snippet below shows how the at method works in pandas:

We can also use the at method to assign a value on a particular index. This is shown in Line 14:

import pandas as pd
df = pd.DataFrame([[0, 2, 3], [0, 4, 1], [10, 20, 30]],
columns=['A', 'B', 'C'])
print("Original Dataframe")
print(df)
print('\n')
print("Get a value")
print(df.at[1, 'B'])
print('\n')
df.at[1, 'C'] = 10
print("New Dataframe")
print(df)

RELATED TAGS

python
pandas

CONTRIBUTOR

Hassaan Waqar
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring