I have a pandas dataframe and wanted to concatenate two columns, while keeping all other columns within the dataframe the same. I tried the following based on the documentation:
df['Code2']= df['Code'] + df['Period']
Yet the result seems to almost work for some rows. While in other rows it doesn't work at all.
See the result below in column "Code2".
+---------+--------+---------+
| Code | Period | Code2 |
+---------+--------+---------+
| 1000000 | 2017 | 1002017 |
| 1100000 | 2017 | 1102017 |
| 1101000 | 2017 | 1103017 |
| 1101100 | 2017 | 1103117 |
| 1101110 | 2017 | 1103127 |
+---------+--------+---------+
Note that the values in column 'Period' are not all equal to 2017. They are only so in the extract above.
The desired result would be the following:
+---------+--------+--------------+
| Code | Period | Code2 |
+---------+--------+--------------+
| 1000000 | 2017 | 1000000_2017 |
| 1100000 | 2017 | 1100000_2017 |
| 1101000 | 2017 | 1101000_2017 |
| 1101100 | 2017 | 1101100_2017 |
| 1101110 | 2017 | 1101110_2017 |
+---------+--------+--------------+