Linkx_lair
Linkx_lair

Reputation: 653

Pandas Dataframe Indexing, Where

So I have a dataframe of wine data

wines_dict = {
'Appellation': list(wine_appellations),
'Ratings': list(wine_ratings),
'Region': list(wine_regions),
'Name': list(wine_names),
'Varietal': list(wine_varietals),
'WineType': list(wine_wine_types),
'RetailPrice': list(wine_retail_prices) 
}

wines_df = pd.DataFrame(
data = wines_dict,
columns =[
    'Region',
    'Ratings',
    'Appellation',
    'Name',
    'Varietal',
    'WineType',
    'RetailPrice'
    ]
)

I am trying to slice it using wines_df.where((wines_df['Ratings'] > 95) & (~pd.isnull(wines_df['Ratings']))) but it is returning back NaN ratings still.

0          NaN
1          NaN
2          NaN
3          NaN
4         97.0
5         98.0
6          NaN

How can i slice it so that it returns all the Non Null values that are greater than 95?

Upvotes: 0

Views: 85

Answers (1)

Vaishali
Vaishali

Reputation: 38415

A simple slice like this should give you the desired output

wines_df[(wines_df['Ratings'] > 95) & (wines_df['Ratings'].notnull())]

Upvotes: 1

Related Questions