簡體   English   中英

使用整數索引重新采樣熊貓系列(添加缺失索引)

[英]Resampling Pandas Series with integer index (add missing index)

我有熊貓系列,例如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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM