简体   繁体   English

熊猫数据框提取值

[英]panda dataframe extracting values

I have a dataframe called "nums" and am trying to find the value of the column "angle" by specifying the values of other columns like this:我有一个名为“nums”的数据框,并试图通过指定其他列的值来查找“角度”列的值,如下所示:

nums[(nums['frame']==300)&(nums['tad']==6)]['angl']

When I do so, I do not get a singular number and cannot do calculations on them.当我这样做时,我没有得到一个单数,也无法对它们进行计算。 What am I doing wrong?我究竟做错了什么? nums数字

First of all, in general you should use .loc rather than concatenate indexes like that:首先,通常你应该使用.loc而不是像这样连接索引:

>>> s = nums.loc[(nums['frame']==300)&(nums['tad']==6), 'angl']

Now, to get the float, you may use the .item() accessor.现在,要获得浮点数,您可以使用.item()访问器。

>>> s.item()
-0.466331

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM