我对 Pandas 比较陌生,所以如果问题的框架不正确,我深表歉意。我有以下数据框
df = pd.DataFrame({'A': ['foo', 'bar', 'foo', 'bar',
'foo', 'bar', 'foo', 'foo'],
'B': ['one', 'one', 'two', 'three',
'two', 'two', 'one', 'three'],
'C': np.random.randn(8)})
A B C
0 foo one 0.469112
1 bar one -0.282863
2 foo two -1.509059
3 bar three -1.135632
4 foo two 1.212112
5 bar two -0.173215
6 foo one 0.119209
7 foo three -1.044236
Run Code Online (Sandbox Code Playgroud)
我想要实现的是以下,
foo_B foo_C bar_B bar_C
0 one 0.469112 - -
1 - - one -0.282863
2 two -1.509059 - - …Run Code Online (Sandbox Code Playgroud)