简体   繁体   English

如何用零填充Pandas DataFrame的缺失行?

[英]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 我有一个Pandas DataFrame df ,它与数据的重要部分有关: df.head()

    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 . 我知道最终的DataFrame的大小必须为214200,因此我想将缺少的ID对应的item_cnt_month设置为零。 How to do it? 怎么做?

我相信您需要:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM