填充缺失的索引,并用0填充其值 [英] Filling the missing index and filling its value with 0
本文介绍了填充缺失的索引,并用0填充其值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个pandas数据框,其列值为索引号
I have a pandas dataframe with a column value as index number
Sales
140 100
142 200
145 300
我想填充缺失的索引,也想用0填充缺失的索引的值
I want to fill the missing index and also want to fill the value of missing index with 0
Sales
140 100
141 0
142 200
143 0
144 0
145 300
我也想填充缺少的值作为缺少的索引号,例如
I also want to fill missing values as the missing index number like
Week_num
140 140
142 142
145 145
Week_Num
140 140
141 141
142 142
143 143
144 144
145 145
我请求您帮助我如何对此进行编码?
I request you to help me how to code this out?
推荐答案
您可以使用reindex
df.reindex(list(range(df.index.min(),df.index.max()+1)),fill_value=0)
Out[471]:
Sales
140 100
141 0
142 200
143 0
144 0
145 300
这篇关于填充缺失的索引,并用0填充其值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文