简体   繁体   中英

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. 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.

Try writing this in terminal: pip install pandas sorry I am a beginner too, will be sad if this does not work. 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.

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. However, this changes if you just have a barebones Python version. 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. To be more specific, Pandas >= 1.0 is required. 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. After that, tried executing import pandas, numpy ,etc. 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 .... . 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. I checked the dependencies and the only one present is pandas>=0.15 . As a result, the suggestion to run pip install pandas or conda install pandas is still valid. The issue is cause by a different module but the root cause is the same

from pandas.core.resample import TimeGrouper

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM