Refer here for the question background. I want to add C
to only column B
.
I need output as:
df
Out[92]:
A B
C
a 0 0
b 1 1
c 2 2
d 3 3
e 4 4
I tried this example as :
dfnew=pd.DataFrame({'a':[1,2,3],'b':[4,5,6]})
columns=[('c','b')] #changed from columns=[('c','a'),('c','b')]
dfnew.columns=pd.MultiIndex.from_tuples(columns)
But that doesn't works. ValueError: Length mismatch: Expected axis has 2 elements, new values have 1 elements