I'm trying to copy all of the values across a subset of rows into a new column using the apply function, but it seems to just copying the entire dataframe range. I'm receiving that subset of the dataframe as a result, though I'm expecting df.loc[index, 'consolidated_commentary'] to contain a concatenated version of the the text in the columns contained within all_commentary_columns
My code is:
for index, row in df[all_commentary_columns].iterrows():
if pd.isna(row).prod():
df.loc[index, 'new_col'] = 'good'
else:
df.loc[index, 'new_col'] = 'bad'
df.loc[index, 'consolidated_commentary'] = df[all_commentary_columns].apply(lambda x: x.loc[all_commentary_columns], axis=1)