How to fillna() with value 0 after calling resample?
<p>Either I don't understand the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.fillna.html">documentation</a> or it is outdated.</p>

<p>If I run </p>

<pre><code>user[["DOC_ACC_DT", "USER_SIGNON_ID"]].groupby("DOC_ACC_DT").agg(["count"]).resample("1D").fillna(value=0, method="ffill")
</code></pre>

<p>It get</p>

<pre><code>TypeError: fillna() got an unexpected keyword argument 'value'
</code></pre>

<p>If I just run</p>

<pre><code>.fillna(0)
</code></pre>

<p>I get </p>

<pre><code>ValueError: Invalid fill method. Expecting pad (ffill), backfill (bfill) or nearest. Got 0
</code></pre>

<p>If I then set</p>

<pre><code>.fillna(0, method="ffill") 
</code></pre>

<p>I get </p>

<pre><code>TypeError: fillna() got multiple values for keyword argument 'method'
</code></pre>

<p>so the only thing that works is</p>

<pre><code>.fillna("ffill")
</code></pre>

<p>but of course that makes just a forward fill. However, I want to replace <code>NaN</code> with zeros. What am I doing wrong here?</p>

<p>The only workaround close to using <code>fillna</code> directly would be to call it after performing <code>.head(len(df.index))</code>. </p>

<p>I'm presuming <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.head.html" rel="nofollow"><code>DF.head</code></a> to be useful in this case mainly because when resample function is applied to a groupby object, it will act as a filter on the input, returning a reduced shape of the original due to elimination of groups.</p>

<p>Calling <code>DF.head()</code> does not get affected by this transformation and returns the entire <code>DF</code>.</p>

<p><strong>Demo:</strong></p>

<pre><code>np.random.seed(42)

df = pd.DataFrame(np.random.randn(10, 2),
              index=pd.date_range('1/1/2016', freq='10D', periods=10),
              columns=['A', 'B']).reset_index()

df
       index         A         B
0 2016-01-01  0.496714 -0.138264
1 2016-01-11  0.647689  1.523030
2 2016-01-21 -0.234153 -0.234137
3 2016-01-31  1.579213  0.767435
4 2016-02-10 -0.469474  0.542560
5 2016-02-20 -0.463418 -0.465730
6 2016-03-01  0.241962 -1.913280
7 2016-03-11 -1.724918 -0.562288
8 2016-03-21 -1.012831  0.314247
9 2016-03-31 -0.908024 -1.412304
</code></pre>

<p><strong>Operations:</strong></p>

<pre><code>resampled_group = df[['index', 'A']].groupby(['index'])['A'].agg('count').resample('2D')
resampled_group.head(len(resampled_group.index)).fillna(0).head(20)

index
2016-01-01    1.0
2016-01-03    0.0
2016-01-05    0.0
2016-01-07    0.0
2016-01-09    0.0
2016-01-11    1.0
2016-01-13    0.0
2016-01-15    0.0
2016-01-17    0.0
2016-01-19    0.0
2016-01-21    1.0
2016-01-23    0.0
2016-01-25    0.0
2016-01-27    0.0
2016-01-29    0.0
2016-01-31    1.0
2016-02-02    0.0
2016-02-04    0.0
2016-02-06    0.0
2016-02-08    0.0
Freq: 2D, Name: A, dtype: float64
</code></pre>

python pandas