我有一个这样的数据框:
我正在尝试像这样重塑它:
对于我的生活,我无法做到这一点。
我认为 usingdf.pivot_table会起作用,但它对分数进行了某种平均。
我已经搜索过,但找不到类似的问题。大多数重塑问题都不想扩大数据集。
任何建议表示赞赏。
df = [ {'id' : '1', 'score_type': 'test_01', 'score': 1},
{'id' : '1', 'score_type': 'test_02', 'score': 2},
{'id' : '1', 'score_type': 'test_03', 'score': 3},
{'id' : '1', 'score_type': 'test_04', 'score': 4},
{'id' : '2', 'score_type': 'test_01', 'score': 5},
{'id' : '2', 'score_type': 'test_02', 'score': 6},
{'id' : '2', 'score_type': 'test_03', 'score': 7},
{'id' : '2', 'score_type': 'test_04', 'score': 8}
]
df = pd.DataFrame(df)
df = df[['id', 'score_type', 'score']]
df
UYOU
犯罪嫌疑人X
相关分类