[英]Pandas groups() method not returning the group names
创建了一个 pandas dataframe 并尝试使用列名进行分组。 分组确实发生了,但由于某种原因,当我尝试使用 groups() 方法获取组名时,它没有给出组名。 它返回“TypeError:'PrettyDict' object 不可调用”。 此方法以前工作过并用于返回组名,但由于某种原因它不再工作了。 我有什么遗漏吗。 pandas 版本和 python 版本如下所述。 有人可以帮助缩小问题的范围。
>>> data = {'Hemisphere' : ["Northern", "Northern", "Northern", "Southern", "Southern",], 'Country' : ['India', 'USA', 'Canada', 'Australia', 'New Zealand']}
>>> df=pd.DataFrame(data)
>>> df
Hemisphere Country
0 Northern India
1 Northern USA
2 Northern Canada
3 Southern Australia
4 Southern New Zealand
>>> a=df.groupby("Hemisphere")
>>> a.groups()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'PrettyDict' object is not callable
>>> ^D
(orgvenv-v2) pradeep@Pradeeps-MacBook-Pro org-structure % pip freeze
numpy==1.21.4
pandas==1.3.4
python-dateutil==2.8.2
pytz==2021.3
six==1.16.0
(orgvenv-v2) pradeep@Pradeeps-MacBook-Pro org-structure % python
Python 3.8.6 (v3.8.6:db455296be, Sep 23 2020, 13:31:39)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.