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 do you concatenated column value for row in pandas data frame?

I am trying to create a new column with concatenated values from other columns in each row of my dataframe:

here is my current attempt

dataFrame['images/0'] = 'https://img.ssensemedia.com/images/b_white,g_center,f_auto,q_auto:best/' + str(dataFrame['sku']) + '_' + '0' + dataFrame['name']

but this is creating a column with values from all of the other rows too. How do I create a new column for each row from the other values of a row? I cant find a definite answer anywhere.

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 :

I would try with apply():

dataFrame['images/0'] = dataFrame.apply(lambda x: f"https://img.ssensemedia.com/images/b_white,g_center,f_auto,q_auto:best/{x['sku']}_0{x['name']}", axis=1)

By setting axis=1 it will pass row by row to lambda so you can access individual column values with x['column_name'].

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