Trying to concatenate string with integer but unwanted values is getting added
<p>I have a Dataframe which has 2 columns, I am trying to create a new column <code>column3</code> with a logic of concatenating values of <code>column1</code> (String) and <code>column2</code> (int) with a separator ('_'). </p>

<p>Below are the few initial values of the dataframe:</p>

<pre><code>    column1  column2
  0  Andy     1
  1  Ashok    4
  2  Collins  7
</code></pre>

<p>Below are my few attempts :</p>

<pre><code>df['column3'] = df['column1'].apply(lambda x: x + '_' + str(df['column2']))

df['column3'] = df['column1'] + '_' + str(df['column2'])

df['column3'] = pd.Series(df['column1']).str.cat(str(df['column2']), sep='_')
</code></pre>

<p>Below is the result:</p>

<pre><code>0       Andy_0       2\n1       2\n2       1\n3     ...
1       Ashok_0       2\n1       2\n2       1\n3    ...
2       Collins_0       2\n1       2\n2       1\n3  ...
</code></pre>

<p>But (<code>2\n1       2\n2       1\n3     ...</code>) is getting added to the result column3 value and only one value zero(0) is getting appended to the result column3.</p>

<p>Please let me know where the things are getting wrong ?</p>

<p>you don't need to make it so complicated. dataframe support such operation:</p>

<pre><code>df.column1 + "_" + df.column2.astype("str")
</code></pre>

python dataframe