add string at the beging of each row

I would like to add a string at the beginning of each row- either positive or negative – depending on the value in the columns:
enter image description here

I keep getting ValueError, as per screenshot

>Solution :

Use for prefixes by conditions and add to index:

df.index = df['positive'].eq(1).map({True:'positive_', False:'negative_'}) + df.index

Or use numpy.where:

df.index = np.where(df['positive'].eq(1), 'positive_','negative_') + df.index

Leave a Reply