pandas - how to access cell in pandas, equivalent

2020-02-09 00:56发布

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?

2条回答
家丑人穷心不美
2楼-- · 2020-02-09 01:22

You can use iloc (to get by position):

df.iloc[3,4]

I recommend reading the indexing section of the docs.

查看更多
成全新的幸福
3楼-- · 2020-02-09 01:32

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

查看更多
登录 后发表回答