I have been trying to re-order a dataframe in pandas by locating the cell which contains the string negative, delete this row and instead add a new column into the dataframe which distinguishes the rows before the cell which contains the string negative and call them 'POSITIVE' whereas the rows which used to be after the string, call them 'NEGATIVE'.
This is a minimal example of the dataframe:
d = {'col1': [1, 2, 'negative', 4,5],
'col2': [6,7,None, 8,9],
'col3':[10,11,None,12,13] }
data = pd.DataFrame(data=d)
This is what I have been trying to acheive:
arget = {'col1': [1, 2, 4, 5],
'col2': [6,7, 8,9],
'col3':[10,11, 12,13],
'col4':['POSTIVE','POSTIVE','NEGATIVE', 'NEGATIVE' ] }
target = pd.DataFrame(data= target)
I have tried to split the dataframe, then remove the row and then add the new column and finally join them again. I was wondering if there is a better way in pandas to achieve this?