我有這樣的數據幀作爲一個例子缺失值的Python熊貓填充數據幀
import pandas as pd
#create dataframe
df = pd.DataFrame([['DE', 'Table',201705,201705, 1000], ['DE', 'Table',201705,201704, 1000],\
['DE', 'Table',201705,201702, 1000], ['DE', 'Table',201705,201701, 1000],\
['AT', 'Table',201708,201708, 1000], ['AT', 'Table',201708,201706, 1000],\
['AT', 'Table',201708,201705, 1000], ['AT', 'Table',201708,201704, 1000]],\
columns=['ISO','Product','Billed Week', 'Created Week', 'Billings'])
print (df)
ISO Product Billed Week Created Week Billings
0 DE Table 201705 201705 1000
1 DE Table 201705 201704 1000
2 DE Table 201705 201702 1000
3 DE Table 201705 201701 1000
4 AT Table 201708 201708 1000
5 AT Table 201708 201706 1000
6 AT Table 201708 201705 1000
7 AT Table 201708 201704 1000
我需要做的就是填寫一些缺失數據與0比林斯每個GROUPBY [「ISO」,「產品」什麼]在序列中出現中斷的情況下,即在某個星期內沒有創建帳單,因此缺少帳單。它需要基於最大「記賬週數」和「最小創建週數」。即,那就是應該完成的組合,並且沒有按順序中斷。
因此,對於上述情況,丟失記錄,我需要以編程方式添加到數據庫中顯示如下:
ISO Product Billed Week Created Week Billings
0 DE Table 201705 201703 0
1 AT Table 201708 201707 0
我無意中編輯了您的答案,但我已將其恢復。對於那個很抱歉。 – Allen
@Allen完全沒有問題! – su79eu7k