Select Particular Element from pandas DataFrame in Python (2 Examples)

In this tutorial you’ll learn how to access a certain value from a pandas DataFrame in Python.

Creation of Example Data

import pandas as pd                       # Load pandas
my_df = pd.DataFrame({'A':range(1, 6),    # Constructing a pandas DataFrame
                      'B':range(17, 22),
                      'C':range(39, 44)})
print(my_df)
#    A   B   C
# 0  1  17  39
# 1  2  18  40
# 2  3  19  41
# 3  4  20  42
# 4  5  21  43

Example 1: Returning Cell Value Using .at attribute

value1 = my_df.at[2, "C"]                 # Specify column name
print(value1)
# 41

Example 2: Returning Cell Value Using .iat attribute

value2 = my_df.iat[3, 1]                  # Specify column index
print(value2)
# 20

Related Tutorials & Further Resources

Besides that, you might have a look at the other articles on Data Hacks. You can find a selection of related articles about similar topics such as lists and indices below.

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top