I am trying to get a subset of data from a dataframe
, based on two criteria, where Region is like 'nebraska' and where metric1 is not nan
The region filter works, but the nan
filter does not and I am unsure why. Would appreciate some pointers on why it does not work.
Thanks!
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import math
import pyodbc
data = [{ 'Region':'nebraska', 'metric1':50},
{ 'Region':'nebraska', 'metric1':np.nan},
{ 'Region':'nebraska', 'metric1':50},
{ 'Region':'nebraska', 'metric1':50},
{ 'Region':'oaklahoma', 'metric1':np.nan},
{ 'Region':'oaklahoma', 'metric1':50},
{ 'Region':'oaklahoma', 'metric1':np.nan},]
testDataset = pd.DataFrame(data)
testDataset[(testDataset.Region.str.contains('nebraska')) & (testDataset.metric1 != np.nan)]