我有像s = pd.Series({1: 10, 2:11, 4:5, 7:10})
这样的熊猫系列
1 10
2 11
4 5
7 10
dtype: int64
我想重新采样这个系列以获得这样的系列
。1 10
2 11
3 0
4 5
5 0
6 0
7 10
dtype: int64
如果你从另一个程序/代码的另一部分获得你的系列,你可以尝试:
max_range = max(s.index) + 1
s = s.reindex(index=range(1, max_range), fill_value=0)