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


i have dataset number of values below.

>>> a.head()    value  freq 3      9     1 2     11     1 0     12     4 1     15     2 

i need fill in values between integers in value column. example, need insert 1 new row between 9 & 11 filled zeroes, 2 between 12-15. end result should dataset 9-15 'missing' rows zeroes across board.

is there anyway insert new row @ specific location without replacing data? methods i've found involve slicing dataframe @ location appending new row , concatenating remainder.

update: index irrelevant don't worry that.

you didn't should happen index, 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 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -