【发布时间】:2019-05-21 03:39:05
【问题描述】:
我需要插入多索引数据帧:
例如:
这是主要的数据框:
a b c result
1 1 1 6
1 1 2 9
1 2 1 8
1 2 2 11
2 1 1 7
2 1 2 10
2 2 1 9
2 2 2 12
我需要找到结果:
1.3 1.7 1.55
到目前为止,我一直在做的是在里面添加一个 pd.Series 和 NaN 分别为每个索引。
如您所见。这似乎是一种非常低效的方式。
如果有人可以丰富我,我会很高兴。
附: 我花了一些时间查看 SO,如果答案在那里,我错过了:
Fill multi-index Pandas DataFrame with interpolation
Resampling Within a Pandas MultiIndex
pandas multiindex dataframe, ND interpolation for missing values
Fill multi-index Pandas DataFrame with interpolation
算法:
第一阶段:
a b c result
1 1 1 6
1 1 2 9
1 2 1 8
1 2 2 11
1.3 1 1 6.3
1.3 1 2 9.3
1.3 2 1 8.3
1.3 2 2 11.3
2 1 1 7
2 1 2 10
2 2 1 9
2 2 2 12
第二阶段:
a b c result
1 1 1 6
1 1 2 9
1 2 1 8
1 2 2 11
1.3 1 1 6.3
1.3 1 2 9.3
1.3 1.7 1 7.7
1.3 1.7 2 10.7
1.3 2 1 8.3
1.3 2 2 11.3
2 1 1 7
2 1 2 10
2 2 1 9
2 2 2 12
第三阶段:
a b c result
1 1 1 6
1 1 2 9
1 2 1 8
1 2 2 11
1.3 1 1 6.3
1.3 1 2 9.3
1.3 1.7 1 7.7
1.3 1.7 1.55 9.35
1.3 1.7 2 10.7
1.3 2 1 8.3
1.3 2 2 11.3
2 1 1 7
2 1 2 10
2 2 1 9
2 2 2 12
【问题讨论】:
-
每个阶段是什么意思?你是什么意思需要找到'1.3 1.7 1.55'的结果?
-
我写下的阶段是我目前解决问题的方法。第 4 列是前三个列的实际值。把它想象成 4D 函数... f(x,y,z) = w
标签: python python-3.x pandas interpolation