on 2020 Nov 23 10:27 AM
Hi All,
I am referring to this blog and creating a predictive data model - https://blogs.sap.com/2020/04/07/sap-data-intelligence-to-train-export-serve-inference-machine-learn...
I got an error with this code which I keyed in as mentioned in the blog. It says there is no attribute "get_datacollection'. But the example code used the same attribute 'get_datacollection'.
I don't know Python so would appreciate any help in fixing this code.
Thank you.
ws = sapdi.get_workspace(name='Pav_Nov23-ws')
dc = ws.get_datacollection(name='PredictiveMealFactor')
with dc.open('DiabetesData.csv').get_reader() as reader:
df = pd.read_csv(reader)
/opt/conda/lib/python3.7/site-packages/ipykernel_launcher.py:1: DeprecatedWarning: get_workspace is deprecated as of 0.3.30.
"""Entry point for launching an IPython kernel.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-8-b1367336437f> in <module>
1 ws = sapdi.get_workspace(name='Pav_Nov23-ws')
----> 2dc = ws.get_datacollection(name='PredictiveMealFactor')
3 with dc.open('DiabetesData.csv').get_reader() as reader:
4 df = pd.read_csv(reader)
AttributeError: 'NoneType' object has no attribute 'get_datacollection'
Request clarification before answering.
Attribute errors in Python are generally raised when you try to access or call an attribute that a particular object type doesn’t possess. It’s simply because there is no attribute with the name you called, for that Object. This means that you got the error when the “module” does not contain the method you are calling. But it is evident that the method is there, which leads to believe that may be the method was added by you in the source code after you had already imported the file (module). Or, some times packages get deprecated and they rename some functions. If that is true, then you may want to exit and reimport the module once again to be able to access the new method .
You can do it in another way to reimport the module with changes without having to exit the interpreter is to do the following:
reload(myModule)
If you are using python 3.2 or 3.3 you should:
import imp
imp.reload(myModule)
If running Python 3.4 and up, do import importlib, then do:
import importlib
importlib.reload(myModule)
The importlib.reload() method reload a previously imported module. The argument must be a module object, so it must have been successfully imported before .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
64 | |
10 | |
8 | |
8 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.