I have tried all the answers that has been posted on the forum but I keep getting thrown this error
How do I correct this error?
ImportError Traceback (most recent call last)
c:\Users\Godfred King\Desktop\Python\titanic\mlingopractice.ipynb Cell 6 in <cell line: 4>()
2 import sklearn.neighbors._base
3 import sys
----> 4 from missingpy import MissForest
5 sys.modules['sklearn.neighbors.base'] = sklearn.neighbors._base
File c:\Users\Godfred King\AppData\Local\Programs\Python\Python39\lib\site-packages\missingpy\__init__.py:1, in <module>
----> 1 from .knnimpute import KNNImputer
2 from .missforest import MissForest
4 __all__ = ['KNNImputer', 'MissForest']
File c:\Users\Godfred King\AppData\Local\Programs\Python\Python39\lib\site-packages\missingpy\knnimpute.py:13, in <module>
11 from sklearn.utils.validation import check_is_fitted
12 from sklearn.utils.validation import FLOAT_DTYPES
---> 13 from sklearn.neighbors.base import _check_weights
14 from sklearn.neighbors.base import _get_weights
16 from .pairwise_external import pairwise_distances
ImportError: cannot import name '_check_weights' from 'sklearn.neighbors._base' (c:\Users\Godfred King\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\neighbors\_base.py)
I have tried the responses posted here No module named 'sklearn.neighbors.base' still existed after all the suggestions what I can take
but I get the same error
It seems to be correct,
try updating your packages,
Code Output:
Related
I am trying to get data from Eurostat via the eurostat python package (info here).
I am using the following code
import eurostat
df = eurostat.get_data_df('MIGR_ASYPENCTZM')
The data I am trying to get is from this page
It is returning the following error:
MIGR_ASYPENCTZM not found in the Eurostat server
---------------------------------------------------------------------------
UnboundLocalError Traceback (most recent call last)
<ipython-input-10-9520b9c4f8bf> in <module>()
----> 1 df = eurostat.get_data_df('MIGR_ASYPENCTZM')
1 frames
/usr/local/lib/python3.7/dist-packages/eurostat/eurostat.py in get_data(code, flags)
77 except Exception:
78 print("{0} not found in the Eurostat server".format(code))
---> 79 raw_part_data[2] = sub(r"\t", ",", raw_part_data[2])
80 n_text_fields = raw_part_data[0].count(",") + 1
81 if flags == True:
UnboundLocalError: local variable 'raw_part_data' referenced before assignment
Any help is much appreciated :)
Try putting everything in lower case:
df = eurostat.get_data_df('migr_asypenctzm')
I'm trying to calculate the daily returns of stock in percentage format from a CSV file by defining a function.
Here's my code:
def daily_ret(ticker):
return f"{df[ticker].pct_change()*100:.2f}%"
When I call the function, I get this error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-40-7122588f1289> in <module>()
----> 1 daily_ret('AAPL')
<ipython-input-39-7dd6285eb14d> in daily_ret(ticker)
1 def daily_ret(ticker):
----> 2 return f"{df[ticker].pct_change()*100:.2f}%"
TypeError: unsupported format string passed to Series.__format__
Where am I going wrong?
f-strings can't be used to format iterables like that, even Series:
Use map or apply instead:
def daily_ret(ticker):
return (df[ticker].pct_change() * 100).map("{:.2f}%".format)
def daily_ret(ticker):
return (df[ticker].pct_change() * 100).apply("{:.2f}%".format)
import numpy as np
import pandas as pd
df = pd.DataFrame({'A': np.arange(1, 6)})
print(daily_ret('A'))
0 nan%
1 100.00%
2 50.00%
3 33.33%
4 25.00%
Name: A, dtype: object
I have been using jupyter notebook in Anaconda for my research work for few months. for Data preprocessing I am importing pandas every time. But all of a sudden a couple days back I have started getting Importerror, which I never faced before.
import pandas as pd
from pandas import DataFrame
The error I am getting is as follows,
ImportError Traceback (most recent call last)
<ipython-input-5-7dd3504c366f> in <module>
----> 1 import pandas as pd
C:\ProgramData\Anaconda3\lib\site-packages\pandas\__init__.py in <module>
53 import pandas.core.config_init
54
---> 55 from pandas.core.api import (
56 # dtype
57 Int8Dtype,
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\api.py in <module>
13
14 from pandas.core.algorithms import factorize, unique, value_counts
---> 15 from pandas.core.arrays import Categorical
16 from pandas.core.arrays.boolean import BooleanDtype
17 from pandas.core.arrays.integer import (
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\arrays\__init__.py in <module>
5 try_cast_to_ea,
6 )
----> 7 from pandas.core.arrays.boolean import BooleanArray
8 from pandas.core.arrays.categorical import Categorical
9 from pandas.core.arrays.datetimes import DatetimeArray
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\arrays\boolean.py in <module>
26 from pandas.core.dtypes.missing import isna, notna
27
---> 28 from pandas.core import nanops, ops
29 from pandas.core.indexers import check_array_indexer
30
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\nanops.py in <module>
33 from pandas.core.dtypes.missing import isna, na_value_for_dtype, notna
34
---> 35 bn = import_optional_dependency("bottleneck", raise_on_missing=False, on_version="warn")
36 _BOTTLENECK_INSTALLED = bn is not None
37 _USE_BOTTLENECK = False
C:\ProgramData\Anaconda3\lib\site-packages\pandas\compat\_optional.py in import_optional_dependency(name, extra, raise_on_missing, on_version)
96 minimum_version = VERSIONS.get(name)
97 if minimum_version:
---> 98 version = _get_version(module)
99 if distutils.version.LooseVersion(version) < minimum_version:
100 assert on_version in {"warn", "raise", "ignore"}
C:\ProgramData\Anaconda3\lib\site-packages\pandas\compat\_optional.py in _get_version(module)
41
42 if version is None:
---> 43 raise ImportError(f"Can't determine version for {module.__name__}")
44 return version
45
ImportError: Can't determine version for bottleneck
I have never imported bottleneck for my work. And there are other users who work on this same device, but I am not sure if any update or change from other users would cause this error or not. In any case how can I get rid of this error?
Edit:
when I run conda list bottleneck it opens a text file named conda-script.py
with following
import sys
# Before any more imports, leave cwd out of sys.path for internal 'conda shell.*' commands.
# see https://github.com/conda/conda/issues/6549
if len(sys.argv) > 1 and sys.argv[1].startswith('shell.') and sys.path and sys.path[0] == '':
# The standard first entry in sys.path is an empty string,
# and os.path.abspath('') expands to os.getcwd().
del sys.path[0]
if __name__ == '__main__':
from conda.cli import main
sys.exit(main())
I encoutered this issue. Here's what worked for me.
Try to update pandas
conda update pandas
Remove and install bottleneck
conda remove bottleneck
conda install bottleneck
I encountered this after doing a conda update pandas after which conda list bottleneck showed nothing so I simply did conda install bottleneck.
(Not enough reptutation to simply upvote nav's answer.)
Can someone help me figure out what this error is telling me? I don't understand why this csv won't load.
Code:
import pandas as pd
import numpy as np
energy = pd.read_csv('Energy Indicators.csv')
GDP = pd.read_csv('world_bank_new.csv')
ScimEn = pd.read_csv('scimagojr-3.csv')
Error:
UnicodeDecodeError Traceback (most recent call last)
<ipython-input-2-65661166aab4> in <module>()
10
11
---> 12 answer_one()
<ipython-input-2-65661166aab4> in answer_one()
4 energy = pd.read_csv('Energy Indicators.csv')
5 GDP = pd.read_csv('world_bank_new.csv')
----> 6 ScimEn = pd.read_csv('scimagojr-3.csv')
7
8
The read_csv function takes an encoding option. You're going to need to tell Pandas what the file encoding is. Try encoding = "ISO-8859-1".
I am trying to use GraphLab Create with Enthought Canopy iPython but I'm getting an ImportError that seems to be related to unicode. The line is:
ImportError: /home/aaron/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/graphlab/cython/cy_ipc.so: undefined symbol: PyUnicodeUCS4_DecodeUTF8
and this is preceded by:
In [1]: import graphlab
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-4b66ad388e97> in <module>()
----> 1 import graphlab
/home/aaron/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/graphlab/__init__.py in <module>()
5 """
6
----> 7 import graphlab.connect.aws as aws
8
9 import graphlab.deploy
/home/aaron/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/graphlab/connect/aws/__init__.py in <module>()
3 This module defines classes and global functions for interacting with Amazon Web Services.
4 """
----> 5 from _ec2 import get_credentials, launch_EC2, list_instances, set_credentials, status, terminate_EC2
/home/aaron/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/graphlab/connect/aws/_ec2.py in <module>()
15
16 import graphlab.product_key
---> 17 import graphlab.connect.server as glserver
18 import graphlab.connect.main as glconnect
19 from graphlab.connect.main import __catch_and_log__
/home/aaron/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/graphlab/connect/server.py in <module>()
4 """
5
----> 6 from graphlab.cython.cy_ipc import PyCommClient as Client
7 from graphlab.cython.cy_ipc import get_public_secret_key_pair
8 from graphlab_util.config import DEFAULT_CONFIG as default_local_conf
In [1]: import graphlab
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-4b66ad388e97> in <module>()
----> 1 import graphlab
/home/aaron/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/graphlab/__init__.py in <module>()
5 """
6
----> 7 import graphlab.connect.aws as aws
8
9 import graphlab.deploy
/home/aaron/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/graphlab/connect/aws/__init__.py in <module>()
3 This module defines classes and global functions for interacting with Amazon Web Services.
4 """
----> 5 from _ec2 import get_credentials, launch_EC2, list_instances, set_credentials, status, terminate_EC2
/home/aaron/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/graphlab/connect/aws/_ec2.py in <module>()
15
16 import graphlab.product_key
---> 17 import graphlab.connect.server as glserver
18 import graphlab.connect.main as glconnect
19 from graphlab.connect.main import __catch_and_log__
/home/aaron/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/graphlab/connect/server.py in <module>()
4 """
5
----> 6 from graphlab.cython.cy_ipc import PyCommClient as Client
7 from graphlab.cython.cy_ipc import get_public_secret_key_pair
8 from graphlab_util.config import DEFAULT_CONFIG as default_local_conf
The GraphLab forum http://forum.graphlab.com/discussion/84/importerror-undefined-symbol-pyunicodeucs4-decodeutf8 suggests that this is due to Enthought Python being compiled with 2-byte-wide unicode chars. Is there a way to get Enthought to use 4-byte chars since I can't recompile?