I wanted to add a column that would tell me if two of my results were the same so I could calculate a % of true/1 or false/0
def same(closests):
if 'ConvenienceStoreClosest' >= 'ConvenienceStoreClosestOSRM':
return 1
else:
return 0
This is what I tried
df_all['same'] = df_all['ConvenienceStoreClosest'].apply(same)
CodePudding user response:
Never use a loop/apply when you can use vectorial code.
In your case a simple way would be:
df_all['same'] = (df_all['ConvenienceStoreClosest']
.eq(df['ConvenienceStoreClosestOSRM'])
.astype(int)
)