0

Im trying to subset a column of a large data frame with a couple nan/inf values in one of the columns.

I have tried for example something like this.

df = df[df['a'] == 'NaN']

Or

df = df[df['a'] == 'Inf']

How do I reference these types of values within a column?

J_Heads
  • 490
  • 2
  • 11

2 Answers2

0

You know it's a dictionary so you can't use comprehension but you can iterate:

subset = {}

for d in df:
   if d['a']=='Nan':
         subset.update(d)

print subset
dmitryro
  • 3,463
  • 2
  • 20
  • 28
0

NaN is a special value. It is not equal to anything, not even itself. Here's one way to filter by NaN:

import math
df = df[df['a'].apply(lambda x: math.isnan(x))]

Inf is a little easier:

df = df[df['a'] == float('inf')]
Evan Samanas
  • 516
  • 3
  • 6