How can I fill in a missing values in range with Pandas?

You didn’t say what should happen to your Index, so I’m assuming it’s unimportant.

In [12]: df.index = df['value']

In [15]: df.reindex(np.arange(df.value.min(), df.value.max() + 1)).fillna(0)
Out[15]:
       value  freq
value
9          9     1
10         0     0
11        11     1
12        12     4
13         0     0
14         0     0
15        15     2

Leave a Comment