I have the following dataframe that lists information on fast food road stops.
Input
first_stop second_stop third_stop
mcdonalds burger king popeyes
mcdonalds N/A N/A
wendys kfc N/A
taco bell kfc wendys
popeyes kfc panda express
I want to create a new column summary that summarizes the stops like so:
Expected Output
first_stop second_stop third_stop summary
mcdonalds burger king popeyes mcdonalds -> burger king -> popeyes
mcdonalds N/A N/A mcdonalds
wendys kfc N/A wendys -> kfc
taco bell kfc wendys taco bell -> kfc -> wendys
popeyes kfc panda express popeyes -> kfc -> panda express
I cannot simply concatenate the three stop columns because some have N/A values if the stop did not exist. How can i do this in pandas?
I've tried this, but obviously it won't give me what i want:
df['summary'] = df['first_stop'] + '->' + df['second_stop'] + '->' + df['third_stop']