模块'pandas'没有属性'Panel'。

9
我在将字典数据帧转换为面板数据帧时遇到了错误。 panelda = pd.Panel()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-33-e8e84d2172b7> in <module>
     11     panaldata[ticker] = panaldata[ticker][["Open","High","Low","Close","Volume"]]
     12     #print(panaldata[ticker].head())
---> 13 panelda = pd.Panel()
     14 #panelda.minor_axis = ["Open","High","Low","Close","Volume"]
     15 #panelda.major_axis = panel.major_axis.tz_localize(pytz.ist)

c:\miniconda\lib\site-packages\pandas\__init__.py in __getattr__(name)
    242         return _SparseArray
    243 
--> 244     raise AttributeError(f"module 'pandas' has no attribute '{name}'")
    245 
    246 

AttributeError: module 'pandas' has no attribute 'Panel'

是的,pd.Panel已经被弃用了。 - Scott Boston
1个回答

9

我自己找到了答案,原来我使用的是最新版的Pandas v1.2.0,从0.25.0版本开始,Pandas模块中已经移除了panel。

print(pd.__version__)
print(np.__version__)
1.2.0
1.19.4

来自0.25.0 / 1.2.0发行说明:

Warning: The panel has been fully removed. For N-D labeled data structures, please use xarray

除非你想使用xarray,否则你需要卸载并安装该版本之前的版本。


我在使用xarray=0.11.3时遇到了问题,因为需要python3.7。我的解决方案是conda uninstall pandas然后conda install -c conda-forge pandas=0.24。感谢您的帮助。 - Under-qualified NASA Intern

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接