If I have a pandas DataFrame object, how do I simply access a cell? In R, assuming my data.frame is called df, I can access the 3rd row and 4th column by
df[3,4]
What is the equivalent in python?
get_value() function is used to quickly retrieve the single value in the data frame at the passed column and index. The input to the function is the row label and the column label.
Select Data Using Location Index (. This means that you can use dataframe. iloc[0:1, 0:1] to select the cell value at the intersection of the first row and first column of the dataframe. You can expand the range for either the row index or column index to select more data.
You can use iloc (to get by position):
df.iloc[3,4]
I recommend reading the indexing section of the docs.
If you want to access the cell based on the column and row labels, use at
:
df.at["Year","Temperature"]
This will return the cell intersected by the row "Year" and the column "Temperature".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With