潜在错误:Pandas MultiIndex

我下载了最新的熊猫pandas-0.14.0rc1-39-g9d01fe1.win-amd64-py2.7.exe.考虑

np.random.seed(1234)

# params, initials
T = 100 # time
N = 80 # firms
TIndex = np.arange(0, T)
FIndex = np.arange(0, N)

index = pd.MultiIndex.from_product([TIndex, FIndex], names=['time', 'firm'])
df = pd.DataFrame(-999, columns=['A', 'w', 'l', 'a', 'x', 'X', 'd', 'profit'], index=index)
t, n = 0, 2
someValues = np.random.randint(0, 5, size=N)
df.loc[(t,n), 'X'] = 0

pd.__version__
df.loc[(t,n), 'X']

给我输出

Out[17]: '0.14.0rc1-39-g9d01fe1'
Out[18]: -999

而且,如果不指定内容,我们甚至无法检查实际设置的值:

import numpy as np
from matplotlib import pyplot
import pandas as pd

np.random.seed(1234)



# params, initials
T = 100 # time
N = 80 # firms
TIndex = np.arange(0, T)
FIndex = np.arange(0, N)

index = pd.MultiIndex.from_product([TIndex, FIndex], names=['time', 'firm'])
df = pd.DataFrame(columns=['A', 'w', 'l', 'a', 'x', 'X', 'd', 'profit'], index=index)
t, n = 0, 2
someValues = np.random.randint(0, 5, size=N)
df.loc[(t,n), 'X'] = 0

pd.__version__
df.loc[(t,n), 'X']

这给我

Out[17]: '0.14.0rc1-39-g9d01fe1'
Traceback (most recent call last):
  File "C:\Users\sdaro\AppData\Local\Enthought\Canopy\User\lib\site-packages\IPython\core\interactiveshell.py", line 2883, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-18-be034dd72c0c>", line 1, in <module>
    df.loc[(t,n), 'X']
  File "C:\Users\sdaro\AppData\Local\Enthought\Canopy\User\lib\site-packages\pandas\core\indexing.py", line 1124, in __getitem__
    return self._getitem_tuple(key)
  File "C:\Users\sdaro\AppData\Local\Enthought\Canopy\User\lib\site-packages\pandas\core\indexing.py", line 649, in _getitem_tuple
    return self._getitem_lowerdim(tup)
  File "C:\Users\sdaro\AppData\Local\Enthought\Canopy\User\lib\site-packages\pandas\core\indexing.py", line 757, in _getitem_lowerdim
    return self._getitem_nested_tuple(tup)
  File "C:\Users\sdaro\AppData\Local\Enthought\Canopy\User\lib\site-packages\pandas\core\indexing.py", line 831, in _getitem_nested_tuple
    if obj.ndim < self.ndim:
AttributeError: 'float' object has no attribute 'ndim'

解决方法:

边缘盒未在此处进行测试:https://github.com/pydata/pandas/pull/7191

已在此提交中修复:https://github.com/jreback/pandas/commit/3e509e8d62b6e176f476ba118a3bdca09135bc08

Windows二进制文件将在2小时内启动:http://pandas.pydata.org/pandas-build/dev/;使用最新的日期

相关文章

转载:一文讲述Pandas库的数据读取、数据获取、数据拼接、数...
Pandas是一个开源的第三方Python库,从Numpy和Matplotlib的基...
整体流程登录天池在线编程环境导入pandas和xrld操作EXCEL文件...
 一、numpy小结             二、pandas2.1为...
1、时间偏移DateOffset对象DateOffset类似于时间差Timedelta...
1、pandas内置样式空值高亮highlight_null最大最小值高亮背景...