I’m trying to impute the OPEN_CLS_STS based on the values in DT_CLS.
IF DT_CLS has a date populated then OPEN_CLS_STS should have a value ‘C’. Otherwise OPEN_CLS_STS should have a value ‘O’.
I tried using the function below but it doesn’t seem to work:
def fill_based_on_conditions(project):
if project['DT_CLS'].isnull():
return project['OPEN_CLS_STS'] == 'O'
else:
return project['OPEN_CLS_STS'] == 'C'
Any suggestions?
enter image description here
The desired output is if DT_CLS is populated with a date, then I want to populate OPEN_CLS_STS with ‘C’. Otherwise I want to populate OPEN_CLS_STS with ‘O’.
Derekhe1988 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4
An example with Pandas:
df = pd.DataFrame({"DT_CLS": ["date1", "date2", np.nan, np.nan, "date3"]})
df["OPEN_CLS_STS"] = df["DT_CLS"].map(lambda x: "C" if x is not np.nan else "O")
display(df)