My desired output would be the highlighted column
CodePudding user response:
You can use ord
to convert the letters to numbers, range
to generate a range of all the numbers in between, and chr
to convert the numbers back to letters. Then use df.apply()
with a lambda function and axis=1
to do this for every row:
df['Final'] = df.apply(lambda x: ' '.join(chr(c) for c in range(ord(x['Letter start']), ord(x['Letter finish']) 1)), axis=1)
Output:
>>> df
Letter start Letter finish Final
0 A D A B C D
1 C E C D E
2 K M K L M