I have a dataframe (df) where two columns are of different length. I would like to combine these two columns as one column. How do I do that?
The table looks like the following:
| Col_1 | Col_2 | Col_1 | Col3 |
|---|---|---|---|
| A1 | 12 | A1 | 345 |
| A2 | 34 | A2 | 980 |
| A3 | 098 | A3 | 543 |
| A4 | 8765 | ||
| A5 | 765 |
I would like to combine Col_1 as one column in the table. The output should look like the following:
Desired Output:
| Col_1 | Col_2 | Col3 |
|---|---|---|
| A1 | 12 | 345 |
| A2 | 34 | 980 |
| A3 | 098 | 543 |
| A4 | 8765 | |
| A5 | 765 |
What I tried so far?
df1 = df.columns[0]
df2 = df.columns[2]
df_merge_col = pd.merge(df1, df2, on='Col_1')
or
df["Col_1"] = df["Col_1"].astype(str) + df["Col_1"]