-3

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
PCG
  • 2,049
  • 5
  • 24
  • 42
  • 1
    This may not be the question you want to hear, but why would you do this? Data analysis doesn't care. If the names are always from the same path, then why wouldn't you just prepend the path when you use the record and go to open the file? – Tim Roberts Dec 29 '21 at 21:30
  • Use os set the dir – BENY Dec 29 '21 at 21:35
  • Does this answer your question? [add a string prefix to each value in a string column using Pandas](https://stackoverflow.com/questions/20025882/add-a-string-prefix-to-each-value-in-a-string-column-using-pandas) – Mykola Zotko Dec 29 '21 at 21:38

1 Answers1

0

@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,
Rutangaba
  • 399
  • 3
  • 7