I have a table contains keyword and its occurrence on each year, but if it doesn't occur in some years, those years are missing.
But I need to pad those years with zero now, how can I do it with Pandas dataframe?
My data is like the table below, each keyword should be padded zero up to 13 years from 2003 to 2015.
+---------+------+-------+ | keyword | year | count | +---------+------+-------+ | a | 2003 | 1 | | a | 2004 | 2 | | b | 2003 | 1 | | b | 2005 | 2 | +---------+------+-------+
Desired result:
+---------+------+-------+ | keyword | year | count | +---------+------+-------+ | a | 2003 | 1 | | a | 2004 | 2 | | a | 2005 | 0 | | a | 2006 | 0 | | a | 2007 | 0 | | a | 2008 | 0 | | a | 2009 | 0 | | a | 2010 | 0 | | a | 2011 | 0 | | a | 2012 | 0 | | a | 2013 | 0 | | a | 2014 | 0 | | a | 2015 | 0 | | b | 2003 | 1 | | b | 2004 | 0 | | b | 2005 | 2 | | b | 2006 | 0 | | ... | ... | ... | +---------+------+-------+
How can I do this? I have searched StackOverflow and only find the answers on non-repeating date, but here my years are repeating.