I have a dataframe as below
+---+---+---+
| A | B | C |
+---+---+---+
| 1 | 0 | 0 |
+---+---+---+
| 0 | 0 | 1 |
+---+---+---+
| 2 | 1 | 1 |
+---+---+---+
| 3 | 1 | 2 |
+---+---+---+
| 4 | 2 | 3 |
+---+---+---+
df = pd.DataFrame({
'A':[1,0,2,3,4],
'B':[0,0,1,1,2],
'C':[0,1,1,2,3]
})
My objective is to concatenate each element with it's corresponding column name and produce a series.
I tried below
df.dot(df.columns +', ').str[:-2]
what I get is
+---------------------------+
| A |
+---------------------------+
| C |
+---------------------------+
| A, A, B, C |
+---------------------------+
| A, A, A, B, C, C |
+---------------------------+
| A, A, A, A, B, B, C, C, C |
+---------------------------+
But, I want is
+------------+
| A |
+------------+
| C |
+------------+
| 2A, B, C |
+------------+
| 3A, B, 2C |
+------------+
| 4A, 2B, 3C |
+------------+
How should I change my code to achieve this?