'Pandas transformation, duplicate index values to column values

I have the following pandas dataframe:

    0
0                      
A   0
B   0
C   0
C   4
A   1
A   7

Now there are some index letter (A and C) that appear multiple times. I want the values of these index letters on a extra column beside instead of a extra row. The desired pandas dataframe looks like:

    0   1       3
0                      
A   0   1       7
B   0   np.nan  np.nan
C   0   4       np.nan

Anything would help!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source