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

How to add prefix to values in one column if not null using pandas

I have a data frame in which I need to add prefix to rows from one of the columns if it’s not null

   Name  marks
0   Tom     99
1  Jack     98
2  Nan     95
3  juli     90

how can I add the prefix= "/new/" to the column Name if not null?
so the New df will look like the following:

   Name       marks
0  /new/Tom    99
1  /new/ Jack  98
2  Nan         95
3  /new/juli   90

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 :

like this I think

df['Name']=np.where(df['marks'].notna(),df['Name']+'/new/',df['Name'])
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