pandas value_couts遇到的问题

来源:互联网 发布:万网单域名控制台登录 编辑:程序博客网 时间:2024/06/08 07:24

python 使用pandas的value_counts函数时,出现错误

Traceback (most recent call last):
  File "/Users/lumingshu/PycharmProjects/shunfeng/splitFile.py", line 34, in <module>
    print data2['预测分级A'].value_counts(ascending=False)
  File "/Users/lumingshu/Library/Python/2.7/lib/python/site-packages/pandas/core/series.py", line 601, in __getitem__
    result = self.index.get_value(self, key)
  File "/Users/lumingshu/Library/Python/2.7/lib/python/site-packages/pandas/indexes/base.py", line 2169, in get_value
    tz=getattr(series.dtype, 'tz', None))
  File "pandas/index.pyx", line 105, in pandas.index.IndexEngine.get_value (pandas/index.c:3567)
  File "pandas/index.pyx", line 113, in pandas.index.IndexEngine.get_value (pandas/index.c:3250)
  File "pandas/index.pyx", line 163, in pandas.index.IndexEngine.get_loc (pandas/index.c:4373)
KeyError: '\xe9\xa2\x84\xe6\xb5\x8b\xe5\x88\x86\xe7\xba\xa7A'


问题:对Series类型(变量data)使用value_counts, 错误的写成了data['a'].value_counts(), 应该是 data.value_counts()