[英]How to solve the problem "No module named 'pandas.core.resample'"?
I am practicing the coding with "Machine Learning for Financial Risk Management with Python Algorithms for Modeling Risk (Abdullah Karasan)" in Chapter 1. I have successfully accessed the time series data of energy capacity utilization from the FRED for the period of 2010–2020, and followed the codes on book to remove its seasonality.我正在使用第 1 章的“使用 Python 风险建模算法 (Abdullah Karasan) 进行金融风险管理的机器学习”练习编码。我已成功访问 FRED 2010-2020 年期间能源产能利用率的时间序列数据,并按照书上的代码删除其季节性。 However, One error occurred when I tried to resample the energy series with the following codes, for which I failed to find relevant solutions:
但是,当我尝试使用以下代码重新采样能量序列时出现一个错误,我未能找到相关解决方案:
In [10]: from fredapi import Fred
import statsmodels.api as sm
In [11]: fred = Fred(api_key='insert you api key')
In [12]: energy = fred.get_series("CAPUTLG2211A2S",observation_start="2010-01-01",observation_end="2020-12-31")
In [20]: seasonal_index = energy.resample('Q').mean()
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-44-a3904e416c86> in <module>
----> 1 seasonal_index = energy.resample('Q').mean()
2 seasonal_index
D:\anaconda\lib\site-packages\pandas\core\generic.py in resample(self, rule, how, axis, fill_method, closed, label, convention, kind, loffset, limit, base, on, level)
ModuleNotFoundError: No module named 'pandas.core.resample'
I am a beginner of Python in Finance working on this topic solely, so I have no ideas of this problem.我是金融领域的 Python 初学者,专门研究这个主题,所以我对这个问题一无所知。
Try writing this in terminal: pip install pandas
sorry I am a beginner too, will be sad if this does not work.尝试在终端中写这个:
pip install pandas
对不起,我也是一个初学者,如果这不起作用会很伤心。 I use an installer to make it easy.我使用安装程序来简化它。
Personally, I think that @UserThatProgram'sHorribly answer is totally on point but still want to add a few things that might be useful for you in the future.就个人而言,我认为@UserThatProgram 的可怕答案完全正确,但仍想添加一些将来可能对您有用的东西。
Usually, all packages have a number of dependencies(packages that might be required to be installed).通常,所有包都有许多依赖项(可能需要安装的包)。 Typically, if you are using a Python distribution like Conda, these are already installed.
通常,如果您使用的是像 Conda 这样的 Python 发行版,则这些已安装。 However, this changes if you just have a barebones Python version.
但是,如果您只有准系统 Python 版本,情况就会改变。 In your case, you tried running a function that would rely on a separate package that hasn't been installed.
在您的情况下,您尝试运行一个依赖于尚未安装的单独包的函数。
In the official statsmodels
installation guide , pandas
(the package that the function relies on) is one of the minimal dependencies.在官方的
statsmodels
安装指南中, pandas
(函数所依赖的包)是最小的依赖之一。 To be more specific, Pandas >= 1.0
is required.更具体地说,
Pandas >= 1.0
是必需的。 Therefore, if you want to be able to use all core functionality of statsmodels
, I would suggest you go there and at least run pip install pandas numpy
, etc. from that list of minimal dependencies.因此,如果您希望能够使用
statsmodels
的所有核心功能,我建议您去那里并至少从该最小依赖项列表中运行pip install pandas numpy
等。 After that, tried executing import pandas, numpy
,etc.之后,尝试执行
import pandas, numpy
等。 to check that the installation has been correct.检查安装是否正确。 This should solve these and most similar problems.
这应该可以解决这些和最类似的问题。
Good luck!祝你好运!
PS If you do have conda installed(which I think you do, judging by the traceback), change pip
to conda install
in order to install those packages through conda.So, it will now look like conda install pandas ....
. PS如果你确实安装了conda(我认为你安装了,从回溯来看),将
pip
更改为conda install
以便通过conda安装这些包。所以,它现在看起来像conda install pandas ....
This will make your life slightly easier in the future这将使您将来的生活更轻松
Correction: just noticed that the issue arises when you call resample()
by the object from fredapi
module.更正:刚刚注意到当您通过
fredapi
模块中的对象调用resample()
时会出现问题。 I checked the dependencies and the only one present is pandas>=0.15
.我检查了依赖项,唯一存在的是
pandas>=0.15
。 As a result, the suggestion to run pip install pandas
or conda install pandas
is still valid.因此,运行
pip install pandas
或conda install pandas
的建议仍然有效。 The issue is cause by a different module but the root cause is the same问题是由不同的模块引起的,但根本原因是相同的
from pandas.core.resample import TimeGrouper
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.