Fillna (forward fill) on a large dataframe efficiently with groupby?
<p>What is the most efficient way to forward fill information in a large dataframe?</p>

<p>I combined about 6 million rows x 50 columns of dimensional data from daily files. I dropped the duplicates and now I have about 200,000 rows of unique data which would track any change that happens to one of the dimensions.  </p>

<p>Unfortunately, some of the raw data is messed up and has null values. How do I efficiently fill in the null data with the previous values?</p>

<pre><code>id       start_date   end_date    is_current  location  dimensions...
xyz987   2016-03-11   2016-04-02  Expired       CA      lots_of_stuff
xyz987   2016-04-03   2016-04-21  Expired       NaN     lots_of_stuff
xyz987   2016-04-22          NaN  Current       CA      lots_of_stuff
</code></pre>

<p>That's the basic shape of the data. The issue is that some dimensions are blank when they shouldn't be (this is an error in the raw data). An example is that for previous rows, the location is filled out for the row but it is blank in the next row. I know that the location has not changed but it is capturing it as a unique row because it is blank.</p>

<p>I assume that I need to do a groupby using the ID field. Is this the correct syntax? Do I need to list all of the columns in the dataframe? </p>

<pre><code>cols = [list of all of the columns in the dataframe]
wfm.groupby(['id'])[cols].fillna(method='ffill', inplace=True)
</code></pre>

<p>There are about 75,000 unique IDs within the 200,000 row dataframe. I tried doing a </p>

<pre><code>df.fillna(method='ffill', inplace=True)
</code></pre>

<p>but I need to do it based on the IDs and I want to make sure that I am being as efficient as possible (it took my computer a long time to read and consolidate all of these files into memory).</p>