4
我试图通过等分分箱我的数据后访问标签(即位置指示器):选择/过滤箱
q = pd.qcut(df["revenue"], 10)
q.head():
7 (317.942, 500.424]
81 (317.942, 500.424]
83 (150.65, 317.942]
84 [0.19, 150.65]
85 (317.942, 500.424]
Name: revenue, dtype: category
Categories (10, object): [[0.19, 150.65] < (150.65, 317.942] < (317.942, 500.424] < (500.424, 734.916] ... (1268.306, 1648.35]
< (1648.35, 1968.758] < (1968.758, 2527.675] < (2527.675, 18690.2]]
In [233]:
这个帖子link显示,你可以做以下的访问标签:
>>> q.labels
但是,当我这样做,我得到:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-246-e806c96b1ab2> in <module>()
----> 1 q.labels
C:\Users\blah\Anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
2666 if (name in self._internal_names_set or name in self._metadata or
2667 name in self._accessors):
-> 2668 return object.__getattribute__(self, name)
2669 else:
2670 if name in self._info_axis:
AttributeError: 'Series' object has no attribute 'labels'
在任何情况下,是什么我想要做的是使用标签来过滤我的数据 - 可能是通过在df中添加一个新的列来表示十分位结果(或分位数)的位置标签。
.labels已在大熊猫的新版本被弃用,你想,我想'q.cat内,z分数.codes'或'q.cat.categories' – jeremycg
'q.cat.categories'实际上解决了我在尝试选择特定分档时遇到的问题。 –