So, I have a table as follows:
start end 5 5 4 8 10 19 4 4
Now what I want to do is, if the value on the two columns in a particular row is equal, then print only one of them in the 3rd column. If they are different, then print - start + "-" + end. The data is in a dataframe. Example is this:
start end range 5 5 5 4 8 4-8 10 19 10-19 4 4 4
This is the code I am trying:
if df['start'] - df['end'] != 0:
df['range'] = df['start'] + "-" + df['end']
else:
df['range'] = df['start']
But this is not working. How can I do this?