I'm adding a column to a dataframe where the column values are determined by comparing two other columns in the dataframe. The code to add the column is:
lst = []
for x in range(len(df)):
if df['ColumnA'][x] > df['ColumnB'][x]:
lst.append(df['ColumnB'][x])
else:
lst.append(df['ColumnA'][x])
df['ColumnC'] = lst
My question is, is there a more efficient/pythonic way to do this? I have been advised in the past to be wary if I'm every looping through every row of a dataframe, so wanted to see if I was missing something. Thank you!