Get continuous dataframe in pandas by filling the missing month with 0
<p>I have a pandas dataframe as shown below where I have Month-Year, need to get the continuous dataframe which should include count as 0 if no rows are found for that month. Excepcted output is shown below. </p>

<h2>Input dataframe</h2>

<pre><code>Month   | Count
--------------
Jan-15  | 10
Feb-15  | 100
Mar-15  | 20
Jul-15  | 10
Sep-15  | 11 
Oct-15  | 1 
Dec-15  | 15
</code></pre>

<h2>Expected Output</h2>

<pre><code>Month   | Count
--------------
Jan-15  | 10
Feb-15  | 100
Mar-15  | 20
Apr-15  | 0
May-15  | 0
Jun-15  | 0
Jul-15  | 10
Aug-15  | 0
Sep-15  | 11 
Oct-15  | 1
Nov-15  | 0 
Dec-15  | 15
</code></pre>

<p>You can set the Month column as the index. It looks like Excel input, if so, it will be parsed at 01.01.2015 so you can resample it as follows:</p>

<pre><code>df.set_index('Month').resample('MS').asfreq().fillna(0)
Out: 
            Count
Month            
2015-01-01   10.0
2015-02-01  100.0
2015-03-01   20.0
2015-04-01    0.0
2015-05-01    0.0
2015-06-01    0.0
2015-07-01   10.0
2015-08-01    0.0
2015-09-01   11.0
2015-10-01    1.0
2015-11-01    0.0
2015-12-01   15.0
</code></pre>

<p>If the month column is not recognized as date, you need to convert it first:</p>

<pre><code>df['Month'] = pd.to_datetime(df['Month'], format='%b-%y')
</code></pre>

python pandas resampling