【发布时间】:2022-01-12 01:16:29
【问题描述】:
我有以下数据框:
| model | metric | final_result | score |
|---|---|---|---|
| Decision Tree | F1 | Pass | 0.57346 |
| Decision Tree | accuracy | Pass | 0.76512 |
| Decision Tree | precision | Pass | 0.6346 |
| Decision Tree | recall | Pass | 0.66512 |
| Decision Tree | F1 | Fail | 0.57346 |
| Decision Tree | accuracy | Fail | 0.76512 |
| Decision Tree | precision | Fail | 0.6346 |
| Decision Tree | recall | Fail | 0.66512 |
| RF | F1 | Pass | 0.57346 |
| RF | accuracy | Pass | 0.76512 |
| RF | precision | Pass | 0.6346 |
| RF | recall | Pass | 0.66512 |
| ... | ... | ... | ... |
我想将表格转换为以下格式:
| Decision Tree | Random Forest | ||
|---|---|---|---|
| final_result | metric | ||
| Pass | accuracy | 0.76512 | 0.76512 |
| precision | 0.6346 | 0.6346 | |
| recall | 0.66512 | 0.66512 | |
| F1 | 0.57436 | 0.57346 | |
| Fail | accuracy | 0.76512 | 0.76512 |
| precision | 0.6346 | 0.6346 | |
| recall | 0.66512 | 0.66512 | |
| F1 | 0.57436 | 0.57346 | |
| ... | ... | ... | ... |
我尝试通过使用pivot_table 函数来做到这一点,如下所示:
pd.pivot_table(modelPerformance, values='score', index=['metric', 'Final Result'], columns='model')
我很困惑,因为很难解释这个问题并在网上找到可能的解决方案,所以我希望这里的人能理解我的最终目标。
【问题讨论】:
标签: python pivot-table data-transform