I'm trying to build a list comprehension that has a conditional to not import nan values, but not having luck. Below is the current code along with the resulting output. What conditional will remove the nans from the list?
def generate_labels(filtered_df, columnName):
    return[
        {'label': i, 'value': i} for i in 
        filtered_df[columnName].unique() 
    ]
generate_labels(df, 'Region')
#Output  
[{'label': 'Americas', 'value': 'Americas'},
     {'label': 'EMEA', 'value': 'EMEA'},
     {'label': nan, 'value': nan},
     {'label': 'APAC ', 'value': 'APAC '}]
def generate_labels(filtered_df, columnName):
    return[
        {'label': i, 'value': i} for i in filtered_df[columnName].dropna().unique() 
    ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With