我下载了最新的大熊猫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'
答案 0 :(得分:3)
此处未测试边缘案例:https://github.com/pydata/pandas/pull/7191
已在此提交中修复:https://github.com/jreback/pandas/commit/3e509e8d62b6e176f476ba118a3bdca09135bc08
Windows二进制文件将在2小时内完成:http://pandas.pydata.org/pandas-build/dev/;使用最新的日期