假设我有以下系列:
import pandas as pd
index1 = pd.IntervalIndex.from_tuples([(1, 3), (2.5, 4), (6, 7)])
x = pd.Series([1, 2, 3], index=index1)
index2 = pd.IntervalIndex.from_tuples([(1, 2), (5, 6.5)])
y = pd.Series([10, 20], index=index2)
z = x+y
Run Code Online (Sandbox Code Playgroud)
理想情况下,这就是我希望 z 的样子:
(1.0, 2.0] 11
(2.0, 2.5] 1
(2.5, 3.0] 3
(3.0, 4.0] 2
(4.0, 5.0] 0
(5.0, 6.0] 20
(6.0, 6.5] 23
(6.5, 7.0] 3
Run Code Online (Sandbox Code Playgroud)
当然,当我添加它们时,我会得到一堆NaNs,因为索引不对齐。
我应该上采样,然后添加吗?(另外……有没有一种奇特的方法可以在熊猫中进行下采样?)
我将如何处理在其自己的索引内具有重叠间隔的系列之一?
我正在尝试跟踪在特定时间上课的学生人数。
我已经修改了课程表,当课程开始和下课时间不同时,我遇到了问题。