In the above sample data, I have empty fields and now the task is to fill the fields with previous values. my columns are dates and the values are a number of items present for that particular article for the specific date. which would be a faster way to interpolate the missing fields. Any suggestions to build the function is appreciated.
1 Answer
-
$\begingroup$ I converted my empty fields with df.replace(r'^\s*$', np.nan, regex=True,inplace=True) and applied df.fillna. But still have some values which has nan $\endgroup$ Nov 21, 2019 at 13:56
-
$\begingroup$ What do they look like? Do they have any value preceding them or are they the first value in the column? $\endgroup$– seraliNov 21, 2019 at 14:20
-
$\begingroup$ it occurs only with the first row and there is no preceding to it. $\endgroup$ Nov 21, 2019 at 14:27
-
$\begingroup$ That is the reason, ffill uses the previous value to fill the next. First row has nothing before it so it cannot be filled by this method. I thought that was the what you wanted? $\endgroup$– seraliNov 21, 2019 at 14:29
-
$\begingroup$ im so stupid, my apologies, I wanted to fill it with the previous values. not the above values. for example, the article LL-23896 has nan need to fill them with 0 and the next values to be interpolated. I hope i was clear. $\endgroup$ Nov 21, 2019 at 14:36