pandas - 我们如何根据级别进行熊猫系列比较?
问题描述
我有一个多索引数据框y_test
:
blockNumber_base10@coarsegrained#1024 address_idx
9441280 2 -0.012421
3 0.001400
6 -0.012696
7 0.003558
15 0.003649
...
9854976 935783 0.000000
935785 0.000000
935786 0.000000
935788 0.000000
935789 0.000000
Name: price@fwd#001024@div#price#m1, Length: 1146272, dtype: float64
我们想与 groupby min 进行比较。
y_test_tmp = y_test.groupby(level = 0).quantile(0.8)
blockNumber_base10@coarsegrained#1024
9441280 0.005130
9442304 0.000973
9443328 0.000461
9444352 0.001354
9445376 0.000921
...
9850880 0.000552
9851904 0.000953
9852928 0.000591
9853952 0.000000
9854976 0.000000
Name: price@fwd#001024@div#price#m1, Length: 405, dtype: float64
我想根据它们与它们进行比较blockNumber_base10@coarsegrained#1024
,所以我想计算 y_test > y_test_tmp
。但我得到了这个错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-318-ad2813982941> in <module>
----> 1 y_test > y_test_tmp
~/anaconda3/lib/python3.8/site-packages/pandas/core/ops/common.py in new_method(self, other)
63 other = item_from_zerodim(other)
64
---> 65 return method(self, other)
66
67 return new_method
~/anaconda3/lib/python3.8/site-packages/pandas/core/arraylike.py in __gt__(self, other)
43 @unpack_zerodim_and_defer("__gt__")
44 def __gt__(self, other):
---> 45 return self._cmp_method(other, operator.gt)
46
47 @unpack_zerodim_and_defer("__ge__")
~/anaconda3/lib/python3.8/site-packages/pandas/core/series.py in _cmp_method(self, other, op)
4971
4972 if isinstance(other, Series) and not self._indexed_same(other):
-> 4973 raise ValueError("Can only compare identically-labeled Series objects")
4974
4975 lvalues = extract_array(self, extract_numpy=True)
ValueError: Can only compare identically-labeled Series objects
有什么建议吗?谢谢!
解决方案
推荐阅读
- javascript - 在 ReactJS 中相应地反转数组和映射按钮
- c# - 初始化其他类的对象?
- gremlin - 如何处理具有大量边的顶点?
- java - 二进制 XML 文件第 7 行:膨胀类 TextView 时出错
- java - 在来自 Jenkins 的自动电子邮件中排除电子邮件附件中的特定文件
- c# - 视图中的 Xamarin MainPage DatePicker 参考
- composer-php - Composer 仅安装到 ONE 项目的另一个目录
- xml - 在线性布局中动态添加多个文本视图
- eclipse - 错误:无法创建文件包/org.eclipse.equinox.p2.tests/testData/ProfilePreferencesTest
- python-3.x - 是否有一个简单的循环来滚动 6 个骰子,直到至少 4 个是相同的数字?