I'm trying to drop rows where there are NaN values in columns 1, 2, and 3 for the years 2019 and 2020.
Here is the dataframe:
col1 col2 col3 col4 year
NaN NaN NaN NaN 2018
NaN NaN NaN NaN 2019
NaN NaN NaN 100 2019
100 200 100 NaN 2020
NaN NaN NaN 200 2020
100 100 150 150 2021
Expected result:
col1 col2 col3 col4 year
NaN NaN NaN NaN 2018
100 200 100 NaN 2020
100 100 150 150 2021
I tried this but it couldn't get it to work:
df.drop(df[(df['year'] == [2019, 2020])
& (df[['col1', 'col2', 'col3']].isnull())].index, inplace=True)