-1

I have a data frame of two columns col1 and col2 I want to fill column 3 from value col1 and col2.

df['col3'] = "122 (xxxxx): Don't show temp df['col1'] and df['col2']"

Does anyone knows how to do please?

salsa
  • 33
  • 1
  • 7
  • What is the issue, exactly? Have you tried anything, done any research? – AMC Mar 17 '20 at 16:02
  • Does this answer your question? [Combine two columns of text in dataframe in pandas/python](https://stackoverflow.com/questions/19377969/combine-two-columns-of-text-in-dataframe-in-pandas-python) – AMC Mar 17 '20 at 16:04

2 Answers2

1

You could try to use apply function:

df['col3'] = df.apply(lambda x: f"122 (xxxxx): Don't show temp {x['col1']} and {x['col2']}", axis=1)
Ivan
  • 61
  • 2
1

You can directly do

df['col3'] = "Text1" + df['col1'] + "Text2" + df['col2']

Might need to use .astype(str) if datatype is not string!

Aroosh Rana
  • 112
  • 11