gpt4 book ai didi

python - 潜在错误 : Pandas MultiIndex

转载 作者:行者123 更新时间:2023-11-28 16:37:36 25 4
gpt4 key购买 nike

我下载了最新的 pandas,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/ ;按日期使用最新的

关于python - 潜在错误 : Pandas MultiIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23805478/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com