Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use Series.map 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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading