[英]Getting cell value by row name and column name from dataframe
Let's say I have the following data frame假设我有以下数据框
name age favorite_color grade
0 Willard Morris 20 blue 88
1 Al Jennings 19 blue 92
2 Omar Mullins 22 yellow 95
3 Spencer McDaniel 21 green 70
And I'm trying to get the grade for Omar which is "95"我正在努力为奥马尔取得“95”的成绩
it can be easily obtained using它可以很容易地使用
ddf = df.loc[[2], ['grade']]
print(ddf)
However, I want to use his name "Omar" instead of using the raw index "2".但是,我想使用他的名字“Omar”而不是使用原始索引“2”。
Is it possible?可能吗?
I tried the following syntax but it didn't work我尝试了以下语法,但没有奏效
ddf = df.loc[['Omar Mullins'], ['grade']]
Try this:尝试这个:
ddf = df[df['name'] == 'Omar Mullins']['grade']
to output the grade
values.输出
grade
值。
Instead:反而:
ddf = df[df['name'] == 'Omar Mullins']
will output the full row.将输出整行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.