Home > Enterprise >  How to update all cell values of Pandas data frame without looping through?
How to update all cell values of Pandas data frame without looping through?

Time:12-30

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

CodePudding user response:

@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,
  • Related