'How to create a Pandas dataframe column based on names from another column? [duplicate]
In a Pandas dataframe (say df), I have the following column:
company_id
1 QW5kcm9z
2 QXNzb2Np
3 QmVs
4 RGFub25l
5 RWNvdG9u
6 RmVycmVy
7 R2VuZXJh
8 SGVybw==
9 S2VsbG9n
10 TWFycw==
... ...
I'd like to create another colmun based on this column with "./Pics/" at the beginning and ".png" at the end, so the first value would be: ./Pics/QW5kcm9z.png
Solution 1:[1]
Use:
df['new'] = './Pics/'+ df.company_id + '.png'
print (df)
company_id new
1 QW5kcm9z ./Pics/QW5kcm9z.png
2 QXNzb2Np ./Pics/QXNzb2Np.png
3 QmVs ./Pics/QmVs.png
4 RGFub25l ./Pics/RGFub25l.png
5 RWNvdG9u ./Pics/RWNvdG9u.png
6 RmVycmVy ./Pics/RmVycmVy.png
7 R2VuZXJh ./Pics/R2VuZXJh.png
8 SGVybw== ./Pics/SGVybw==.png
9 S2VsbG9n ./Pics/S2VsbG9n.png
10 TWFycw== ./Pics/TWFycw==.png
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
