Home > database >  How to concatenate two column and one variable in a new column
How to concatenate two column and one variable in a new column

Time:03-22

I have a str variable and two string columns I want to save in a new column as ID I do this

pos = 9
colname - df.columns[pos]
df['CNV_ID'] = str(colname)   str(df['col1'])   str(df['col2'])

For I reason I do not understand this destroys the structure of my df (cannot copy and paste df as working in a secure computer but can show screenshots.

enter image description here

What is going on??

If I save it and open it with a text editor, it looks even worse

enter image description here

(Sorry for posting pictures, I know it is not good practice but, nothing I can do)

CodePudding user response:

Use astype(str):

df['CNV_ID'] = colname   df['col1'].astype(str)   df['col2'].astype(str)
  • Related