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 update all cell values of Pandas data frame without looping through?

I have a Pandas data frame read from csv file as follows :

file name, score, X, Y
a.png, 0.5, 1, 5
b.png, 0.1, 2, 5
c.png, 0.9, 4, 3

I need to joint the full path to the ‘file name’ in the first column. What’s the best way to do it without looping through each item?

file name, score, X, Y
C:\temp\a.png, 0.5, 1, 5
C:\temp\b.png, 0.1, 2, 5
C:\temp\c.png, 0.9, 4, 3

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 :

@PCG, try this:

df['filename'].apply(lambda x: str("C:\temp\\")+ str(x))

Output:

0    C:\temp\a.png,
1    C:\temp\b.png,
2    C:\temp\c.png,
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