.at[]

aSagCoder's avatar
Published Sep 1, 2024
Contribute to Docs

In Pandas, the .at[] function is used as an accessor to fetch a specific value from a DataFrame using row and column pairs.

Syntax

dataframe.at[index, label]
  • index: The index (or row label) where the specific value is located or where you want to set the value.
  • label: The label (or column name) where the specific value is located or where you want to set the value.

The result returned is a single element located at the specified position within the DataFrame.

Example

The following example shows the use of the .at[] accessor function:

import pandas as pd
# Create a DataFrame with two columns 'A' and 'B'
df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
# Use .at[] to access the element at row 0, column 'B'
element = df.at[0, 'B']
# Print the accessed element
print(element)

The output of the code is as follows:

3

Codebyte Example

Run the following codebyte to understand how the .at[] accessor is used to access a specific element in a DataFrame at a given row and column label:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn Python:Pandas on Codecademy