Skip to content
Advertisement

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['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

Advertisement

Answer

First of all, in general you should use .loc rather than concatenate indexes like that:

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

Now, to get the float, you may use the .item() accessor.

>>> s.item()
-0.466331
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement