Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pandas - how to access cell in pandas, equivalent of df[3,4] in R

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?

like image 934
bill999 Avatar asked Jan 27 '14 22:01

bill999


People also ask

How do you get a particular column value from a DataFrame 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.

How do you select a specific value in a DataFrame?

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.


2 Answers

You can use iloc (to get by position):

df.iloc[3,4] 

I recommend reading the indexing section of the docs.

like image 164
Andy Hayden Avatar answered Oct 30 '22 23:10

Andy Hayden


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".

like image 22
multigoodverse Avatar answered Oct 31 '22 00:10

multigoodverse