pandas - 如何访问 Pandas 中的单元格,相当于 R 中的 df[3,4]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21393489/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
pandas - how to access cell in pandas, equivalent of df[3,4] in R
提问by bill999
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
如果我有一个 Pandas DataFrame 对象,我如何简单地访问一个单元格?在 R 中,假设我的 data.frame 被称为 df,我可以通过以下方式访问第 3 行和第 4 列
df[3,4]
What is the equivalent in python?
python中的等价物是什么?
回答by Andy Hayden
You can use iloc (to get by position):
您可以使用 iloc (按位置获取):
df.iloc[3,4]
I recommend reading the indexing section of the docs.
回答by multigoodverse
If you want to access the cell based on the column and row labels, use at
:
如果要根据列和行标签访问单元格,请使用at
:
df.at["Year","Temperature"]
This will return the cell intersected by the row "Year" and the column "Temperature".
这将返回与“Year”行和“Temperature”列相交的单元格。