I have a table of various indicators grouped by Date and Code. I am trying to fill missing values with the previous day's data OR if not available - with the next day's data for each Code.
The problem is when I group by 'Code' and 'Date', nothing happens
df = pd.DataFrame([['2019-05-01', 'APL', 15951, 303, 49],
['2019-05-02', 'APL', 16075, 301, 46],
['2019-05-03', 'APL', np.nan, 300, 45],
['2019-05-04', 'APL', 15868, 298.8, 33],
['2019-05-01', 'MSK', 2222, np.nan, np.nan],
['2019-05-02', 'MSK', 2224, 243, 53],
['2019-05-03', 'MSK', 2266, 233, 33],
['2019-05-04', 'MSK', np.nan, 253, 55]],
columns=['Date', 'Code', 'Price', 'Volume', 'ATM'])
Here is what I am trying:
df.groupby(['Code','Date'])['Price','Volume', 'ATM'].fillna(method = 'ffill')