I am trying to concatenate multiple columns as strings to a new one
Given the following example:
| colA | colB | colC |
|---|---|---|
| 0.4 | 2 | test1 |
| 0.7 | 3 | test2 |
| 0.8 | 4 | test3 |
I need the new column
| new column |
|---|
| colA0.4 colB2 colCtest1 colCtest1 |
| colA0.7 colB3 colCtest2 colCtest2 |
| colA0.8 colB4 colCtest3 colCtest3 |
And for instance, I would need to repeat certain columns just like column C
Initially I had the following function :
def create_soup(x):
return ( ('colA' + str(x['colA']) + ' ') * 3
+ (str(x['colB']).replace(',', ' ') + ' ') * 2 )
and i applied like the following
df["soup"] = df.apply(create_soup, axis = 1)
But now I've tried with new ways such as
df['soup'] = df['colA'].apply(lambda x: f"colA{x}")
If you want to know why I can't use the previous function create_soup, it is because I have troubles implementing to my Python class, which is why i'm trying to find alternatives
Much thanks if you can provide any insights, or help