我正在嘗試更正沒有日期的每一行。然后想法只是填補(bǔ)缺失日期之間的空白,并用以前的值完成其他列。 ds SKU Estoque leadtime0 2018-01-02 504777 45 111 2018-01-04 504777 42 112 2018-01-05 504777 41 113 2018-01-09 504777 40 114 2018-01-12 504777 37 115 2018-01-13 504777 36 116 2018-01-15 504777 35 11... ... ... ... ...6629 2018-08-14 857122 11 106630 2018-08-15 857122 10 106631 2018-08-16 857122 9 106632 2018-08-17 857122 7 106633 2018-08-23 857122 14 106634 2018-08-24 857122 13 10我已經(jīng)嘗試過:df.set_index('ds', inplace=True)df = df.resample("D")或者df.resample("D", how='first', fill_method='ffill')但我剛得到這個:DatetimeIndexResampler [freq=<Day>, axis=0, closed=left, label=left, convention=start, base=0]當(dāng)我嘗試:(df.groupby('SKU') .resample('D') .last() .reset_index() .set_index('ds'))我收到此錯誤:ValueError: cannot insert SKU, already exists我試圖得到這個結(jié)果: ds SKU Estoque leadtime0 2018-01-02 504777 45 111 2018-01-03 504777 45 112 2018-01-04 504777 42 113 2018-01-05 504777 41 114 2018-01-06 504777 41 115 2018-01-07 504777 41 116 2018-01-08 504777 41 117 2018-01-09 504777 40 11... ... ... ... ...PS:如果我將日期設(shè)置為索引,我有重復(fù)的索引。我需要首先隔離每個產(chǎn)品(分組依據(jù))
1 回答

慕勒3428872
TA貢獻(xiàn)1848條經(jīng)驗 獲得超6個贊
在您的情況下,您可能需要與 apply
#df.set_index('ds', inplace=True)
df.groupby('SKU').apply(lambda x : x.resample('D').ffill()).reset_index(level=0,drop=True)
添加回答
舉報
0/150
提交
取消