I have a dataframe with a couple of columns that need to have various columns populated depending upon conditions. I wrote out a function, and have been using df.apply
, however this is obviously exceptionally slow. I'm looking for help in creating a faster way to do the following:
def function(df):
if pd.isnull(df['criteria_column']) == True:
return df['return_column']
else:
return
df['new_column'] = df.apply(function, axis=1)
I'd like to do something like:
df['new_column'] = np.where(pd.isnull(df['criteria_column'] == True),
df['return_column'], "")
However this results in ValueError: Could not construct Timestamp from argument <type 'bool'>