# Pandas DataFrame: Get a Single Cell's Value with .at

> Use DataFrame.at or DataFrame.iat to retrieve a single Pandas cell value by row and column label or position, faster than loc or iloc for one cell

**URL:** https://sentry.io/answers/get-the-value-of-a-dataframe-cell-in-python-pandas/

---

## The Problem

How can I retrieve the value of a single cell in a Python Pandas DataFrame? I want just the value, not a new DataFrame with only one cell.

## The Solution

We can retrieve the value of a single DataFrame cell using the [`DataFrame.at`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.at.html) property, providing the row and column labels for the element we want to access:

```python
import pandas

# Set up and print the DataFrame
data = {
    "Product": ["Apple", "Orange", "Pear"],
    "Cost Price": [1, 2, 3],
    "Selling Price": [2, 3, 4],
}
df = pandas.DataFrame(data)
print(df)
print()

# will print:
#   Product  Cost Price  Selling Price
# 0   Apple           1              2
# 1  Orange           2              3
# 2    Pear           3              4

# Retrieve "Pear"
df_cell = df.at[2, "Product"]
print(df_cell)  # will print "Pear"
```

Note that the value `2` here is being interpreted as a row label, rather than a row number. If we want to access the value of a cell using the indices of its row and column rather than the label, we can use [`DataFrame.iat`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.iat.html):

```python
# Retrieve "Pear"
df_cell = df.iat[2, 0]
print(df_cell) # will print "Pear"
```

We can also use [`DataFrame.loc`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.loc.html) in place of `DataFrame.at`, or [`DataFrame.iloc`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.iloc.html) in place of `DataFrame.iat`:

```python
# Retrieve "Pear"
df_cell = df.loc[2, "Product"]
print(df_cell)  # will print "Pear"

# Retrieve "Pear"
df_cell_by_index = df.iloc[2, 0]
print(df_cell_by_index)  # will print "Pear"
```

`DataFrame.loc` and `DataFrame.iloc` are more flexible, general accessors, which can both be used to select arbitrarily sized portions of a DataFrame. `DataFrame.at` and `DataFrame.iat`, on the other hand, are both optimized for retrieving the value of a single cell, so the versions of our code using one of these functions will run faster. This will be especially noticeable with large DataFrames.

---

*Source: [sentry.io/answers/get-the-value-of-a-dataframe-cell-in-python-pandas/](https://sentry.io/answers/get-the-value-of-a-dataframe-cell-in-python-pandas/)*
