I've a dataframe like below
+---+----+---+----+----+-----+------+
| X | XX | Y | YY | ZZ | ZZZ | ZZZZ |
+---+----+---+----+----+-----+------+
| 0 | 1 | 1 | 0 | 0 | 1 | 0 |
+---+----+---+----+----+-----+------+
| 1 | 0 | 0 | 1 | 0 | 0 | 1 |
+---+----+---+----+----+-----+------+
| 0 | 1 | 0 | 0 | 1 | 0 | 0 |
+---+----+---+----+----+-----+------+
| 0 | 0 | 1 | 0 | 0 | 0 | 0 |
+---+----+---+----+----+-----+------+
df = pd.DataFrame({
'X':[0,1,0,0],
'XX':[1,0,1,0],
'Y':[1,0,0,1],
'YY':[0,1,0,0],
'ZZ':[0,0,1,0],
'ZZZ':[1,0,0,0],
'ZZZZ':[0,1,0,0]
})
I want to concatenate the dataframe row values into one with consistent padding.
I tried the below code
df.dot(df.columns +' | ')
| sign with extra spaces before and after.
what I get is
0 XX | Y | ZZZ |
1 X | YY | ZZZZ |
2 XX | ZZ |
3 Y |
dtype: object
But, what I expect to receive is
0 XX | Y | ZZZ |
1 X | YY | ZZZZ |
2 XX | ZZ |
3 Y |
dtype: object
notice the alignment in | sign.
How can I modify my code to add this extra variable padding spaces? pandas or numpy solution preferred.