I have the current dataframe:
| Date | Source | Type | Visits | Sales |
|---|---|---|---|---|
| 01/01/2020 | Source1 | Type1 | 100 | 10 |
| 01/01/2020 | Source2 | Type1 | 150 | 5 |
| 02/01/2020 | Source1 | Type1 | NaN | NaN |
| 02/01/2020 | Source2 | Type1 | 125 | 15 |
| 03/01/2020 | Source1 | Type2 | 150 | 18 |
| 03/01/2020 | Source2 | Type2 | NaN | NaN |
| 04/01/2020 | Source1 | Type2 | 150 | 25 |
| 04/01/2020 | Source2 | Type2 | 120 | 05 |
What I'd like to do is a simple .interpolate() for the missing data however I need to group it by the Source and Type to keep the data as accurate as possible rather than basing it on the above and below rows which aren't relevant.
I've got to this stage:
df_fixed = df[['Source','Type','Visits','Sales']].loc[(df['Source'] == 'Source1') & (df['Type'] == 'Type1')].interpolate()
Which does the first step but can't get any further and feel like there's an easier way.
What would be the most elegant way to complete this?
