I have the following data frame:
dataset = {
'String': ["ABCDEF","HIJABC","ABCHIJ","DEFABC"],
'Bool':[True,True,False,False],
'Number':[10,20,40,50]}
df = pd.DataFrame(dataset)
String Bool Number
0 ABCDEF True 10
1 HIJABC True 20
2 ABCHIJ False 40
3 DEFABC False 50
I would like to sum the rows of the column Number where Bool is False to the rows where Bool is True:
The rows can be matched and summed together if the reverse of String of one row is not equal to the String of the row.
In this case
ABCHIJwhereboolisFalseis not equal to the reverse ofABCDEFso I sum the numbers: 10+40.HIJABCwhereBoolisTrueis summed toDEFABCwhereBoolisFalsethe outcome is70
Expected output:
String Bool Number
0 ABCDEF True 50
1 HIJABC True 70
2 ABCHIJ False 40
3 DEFABC False 50
I hope my explanation was good enough, is there a way to achieve the above outcome ?
4 XYZ False 70?DEFABCis not reversed string ofABCDEF!!!