获取错误numpy.ndarray'对象在python中没有属性'append'

时间:2014-03-31 14:31:11

标签: python-2.7 pandas

  1. 我发现了一个不合逻辑的错误      ' numpy.ndarray'对象没有属性'追加'当我在python中运行groupby的代码命令是

    df = df.groupby(df.columns[1]).sum().reset_index()

  2. 任何帮助请继续

1 个答案:

答案 0 :(得分:0)

对于后代,所以我可以在google上找到它。

另外:Python 2.7.6,Pandas 0.13.1。

问题看起来像是一个空数据帧。熊猫们,如果你正在聆听,你可以在DataFrame.reset_index()方法中进行一些输入检查。

Bens-MacBook-Pro:RightAnalytics bdundee$ python
Python 2.7.6 (default, Feb  5 2014, 15:46:04) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> df = pd.DataFrame()
>>> df.reset_index()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/frame.py", line 2472, in reset_index
    new_obj.insert(0, name, values)
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/frame.py", line 1965, in insert
    loc, column, value, allow_duplicates=allow_duplicates)
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/internals.py", line 2918, in insert
    self._add_new_block(item, value, loc=loc)
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/internals.py", line 3042, in _add_new_block
    self.blocks.append(new_block)
AttributeError: 'numpy.ndarray' object has no attribute 'append'
>>>