0

There are three columns: years_one,year_two, and binary

The idea is to see if year_two is NaN (missing value) and if column binary is True replace year_two column missing value (None) with float 2021 otherwise leave as is.

import pandas as pd 
import numpy as np

df = pd.DataFrame()
df['year_one'] = [2017.000,2019.000,2018.000]
df['year_two'] = [None, None, 2019.000]
df['binary'] = [True, True, False]

attempt:

df_t = pd.DataFrame()
df_t = df.loc[((df['year_two'].isnull()) == True & (df['binary'] == True))].replace(np.nan, float(2021))
Adrian023
  • 3
  • 4

0 Answers0