Josh
Josh

Reputation: 12781

Unable to filter values in a DataFrame. NaN's in the output

I have the following one-column DataFrame, df:

timestamp                           values
2014-10-06 18:00:37.400000-04:00  0.000000    
2014-10-06 18:00:39.600000-04:00  0.000000    
2014-10-06 18:00:41.800000-04:00  2.683493    
2014-10-06 18:00:44-04:00         1.199321    

When I do df[df>0] I get:

timestamp                           values
2014-10-06 18:00:37.400000-04:00 NaN          
2014-10-06 18:00:39.600000-04:00 NaN          
2014-10-06 18:00:41.800000-04:00  2.683493    
2014-10-06 18:00:44-04:00         1.199321    

while I would expect to only get:

timestamp                           values
2014-10-06 18:00:41.800000-04:00  2.683493    
2014-10-06 18:00:44-04:00         1.199321    

Is this expected? I know I can apply dropna()on this output, but isn't the above already supposed to filter out the values I ask for? (it typically works on dataframes wihtout having to call dropna)

Upvotes: 0

Views: 82

Answers (1)

Primer
Primer

Reputation: 10302

ts[ts['values']>0] should produce the output you are looking for.

Don't know why but to have the output without NaN you need to specify column(s). I didn't find a way to get rid of NaNs when filtering on the whole dataframe except for .dropna()

Upvotes: 2

Related Questions