[英]How to “flatten” a Panda Panel by summing up specific columns
我仍然使用Pandas和Python來熟悉自己,所以請原諒這是一個簡單的問題。 我也想避免使用一個襯墊,以便在可能的情況下理解底層動作! :)
我已經成功地提取了數據數據,這導致了一個Panel,有四個項目。 每個項目的關鍵是日歷季度:
Item '2015-03-31':
Type Quarterly Sales Ending Inventory
Shoes 123,456 50,000
Purses 33,222 10,000
Item '2015-06-30':
Type Quarterly Sales Ending Inventory
Shoes 12,744 56,000
Purses 15,123 9,000
Item '2015-9-30':
Type Quarterly Sales Ending Inventory
Shoes 15,998 35,000
Purses 11,222 15,000
Item '2015-12-31':
Type Quarterly Sales Ending Inventory
Shoes 12,000 45,000
Purses 9,551 7,000
最后,我想通過總結季度銷售來“扁平化”這一點,但是從最近的條目中獲取類型和結束庫存 ,並將其放在DataFrame中。 所以我的結尾DataFrame將是這樣的:
Type Quarterly Sales Ending Inventory
Shoes 164,198 45,000
Purses 69,118 7,000
我嘗試使用像grouby這樣的函數(例如mypanel.groupby('Type').sum()
),但最終總結了季度銷售 和 結束庫存 ,而我想采用“最近的” 結束庫存 。 一個簡單的“修復”就是獲取生成的DataFrame,然后減去Ending Inventory列的前三個季度的總和,但這看起來非常尷尬。
有什么建議么?
謝謝!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.