Fallen Apart
Fallen Apart

Reputation: 741

How to fill the missing rows of Pandas DataFrame with zeros?

I have a Pandas DataFrame df which relates to the non-trivial part of data: df.head() spits

    item_cnt_month
ID  
2   0.441488
5   0.461178
6   0.262789
10  2.861585
14  3.616117

I know that the final DataFrame has to be of size 214200 and thus I want to put the missing IDs with corresponding item_cnt_month equal to zero . How to do it?

Upvotes: 3

Views: 1063

Answers (1)

jezrael
jezrael

Reputation: 862581

I believe you need:

df = df.reindex(np.arange(214200), fill_value=0)

Upvotes: 4

Related Questions