I've got pandas dataframe with values "along path", with distances, but some of the values are missing. Dataframe looks like this:
Idx AccumDist ValT
0 1 3059 112
1 2 4281 194
2 3 4947 NaN
3 4 5460 NaN
4 5 5811 543
5 6 6021 591
6 7 6289 NaN
7 8 7487 909
8 9 8031 954
9 10 8242 1069
AccumDist and ValT is accumulated data, and some of the ValT are "missing".
What I want to do is to replace NaN in column ValT with averages to from closest "known" data in this column, weighted by AccumDist difference.
Because there could be missing ValT value after another (might be more than 1) I can't use rolling weighted average (or I don't know how to use it), while I still want to average only "closest known" values.
I was thinking about using df.shift(), maybe on some dataframe subset(s), but I'm not really sure how to do it. Thanks for any help or suggestions.
Use
interpolatebased on the accumulated distance. Set that as the index and usemethod='index'. Then assign this calculation back to your DataFrame using the like-sized numpy array.