Issue
I'm trying to compare cell value of dataframe to some strings and concat that matched string in a variable but I'm getting error. Could someone please check..!
route=''
for b in range(10):
route+ = ('-'+ rail[0].index[b] +'-') if (rail[x].index[b] == ('WD' | 'POT' | 'NGI'))
Error I'm getting is:-
unsupported operand type(s) for |: 'str' and 'str'
Edit: Adding some index values to work on
Index(['DW', 'NG', 'NGI', 'DW', 'WD', 'NGI', 'NF', 'FGH', 'NNI',
'DWD','NGH', 'POT', 'NGI', 'DW', 'POT', 'NNGI', 'GH', 'NH', 'NGI',
'WD'])
Solution
Assuming you are trying to check whether your rail[x].index[b]
is either of ('WD' | 'POT' | 'NGI')
on each iteration,
Try the below snippet if it is the case,
route=''
for b in range(10):
route += ('-'+ rail[0].index[b] +'-') if (rail[x].index[b] in ('WD', 'POT', 'NGI'))
Quick Check:
print("WD" == ('WD' | 'POT' | 'NGI'))
TypeError: unsupported operand type(s) for |: 'str' and 'str'
print("WD" in ('WD' , 'POT' , 'NGI'))
True
Answered By - Saravanakumar V
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.