How can I get a value from a cell of a dataframe?
You can use the .at
or .iat
methods to get the value of a specific cell in a DataFrame.
Here's an example:
import pandas as pd
# Create a sample DataFrame
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]})
# Get the value of the cell at row 0 and column 'A'
value = df.at[0, 'A']
print(value)
Watch a video course
Python - The Practical Guide
You can also use the .iat
method if you want to access the cell by its index rather than by its label:
value = df.iat[0, 0]
print(value)
Both .at
and .iat
will return the value of the cell at the specified row and column.