我對 pandas 功能有疑問pd.groupby()。我有數據框data = [{'Shop': 'Venga', 'Item Name': 'Oranges', 'Measure':'Supply Cost', 'Value': '10'}, {'Shop': 'Venga', 'Item Name': 'Oranges', 'Measure':'Product Cost', 'Value': '20'}, {'Shop': 'Venga', 'Item Name': 'Apples', 'Measure':'Supply Cost', 'Value': '5'}, {'Shop': 'Venga', 'Item Name': 'Apples', 'Measure':'Product Cost', 'Value': '60'}, {'Shop': 'Mesto', 'Item Name': 'Oranges', 'Measure':'Supply Cost', 'Value': '15'}, {'Shop': 'Mesto', 'Item Name': 'Oranges', 'Measure':'Product Cost', 'Value': '10'}, {'Shop': 'Mesto', 'Item Name': 'Apples', 'Measure':'Supply Cost', 'Value': '80'}, {'Shop': 'Mesto', 'Item Name': 'Apples', 'Measure':'Product Cost', 'Value': '5'}, ]我想將我的類別移至Measure列并使其看起來像這樣:我嘗試過跑步,data.groupby(['Measure'], axis = 1).sum()但對我來說根本不起作用。
如何在 pandas 中聚合總和并將唯一行值轉換為列名稱?
慕運維8079593
2023-10-06 10:56:47