.at[]
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 elementprint(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:
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.