Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 潜在错误:熊猫多重索引_Python_Pandas - Fatal编程技术网

Python 潜在错误:熊猫多重索引

Python 潜在错误:熊猫多重索引,python,pandas,Python,Pandas,我下载了最新的熊猫,pandas-0.14.0rc1-39-g9d01fe1.win-amd64-py2.7.exe。考虑 np.random.seed(1234) 给我输出 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(

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

np.random.seed(1234)

给我输出

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'
Out[17]:“0.14.0rc1-39-g9d01fe1”
回溯(最近一次呼叫最后一次):
文件“C:\Users\sdaro\AppData\Local\enthund\Canopy\User\lib\site packages\IPython\core\interactiveshell.py”,第2883行,运行代码
exec(代码对象、self.user\u全局、self.user\n)
文件“”,第1行,在
测向位置[(t,n),'X']
文件“C:\Users\sdaro\AppData\Local\enthund\Canopy\User\lib\site packages\pandas\core\index.py”,第1124行,在u getitem中__
返回self.\u getitem\u元组(键)
文件“C:\Users\sdaro\AppData\Local\enthught\Canopy\User\lib\site packages\pandas\core\index.py”,第649行,在_getitem\元组中
返回self.\u getitem\u lowerdim(tup)
文件“C:\Users\sdaro\AppData\Local\enthund\Canopy\User\lib\site packages\pandas\core\index.py”,第757行,位于_getitem\u lowerdim中
返回self.\u getitem\u嵌套\u元组(tup)
文件“C:\Users\sdaro\AppData\Local\enthught\Canopy\User\lib\site packages\pandas\core\index.py”,第831行,位于\u getitem\u嵌套\u元组中
如果obj.ndim
此处未测试边缘案例:

在此提交中修复了以下问题:


windows二进制文件将在2小时内启动:;使用最新的截止日期。loc[(t,n),'X']返回标量。你想要df.loc[t,'X']`吗?
df.loc[t,'X']
按预期工作,只需使用
(t,n)
它不工作。我将在2小时后检查二进制文件:)=
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'