我正在尝试在Jupyter Notebook中运行以下代码,但是在下面给出了错误。 错误粘贴在下方,有人可以帮我解决问题吗?
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
values = np.array([1, 3, 2, 4, 1, 6, 4])
example_df = pd.DataFrame({
'value': values,
'even': values % 2 == 0,
'above_three': values > 3
}, index=['a', 'b', 'c', 'd', 'e', 'f', 'g'])
# Change False to True for this block of code to see what it does
# groupby() without as_index
if True:
first_even = example_df.groupby('even').first()
print first_even
print first_even['even'] # Causes an error. 'even' is no longer a column in the DataFrame
错误:
ImportError Traceback (most recent call last)
<ipython-input-414-7b44697e4465> in <module>()
2 import numpy as np
3 import pandas as pd
----> 4 import seaborn as sns
5
6 values = np.array([1, 3, 2, 4, 1, 6, 4])
C:\Users\...\Anaconda2\lib\site-packages\seaborn\__init__.py in <module>()
4
5 # Import seaborn objects
----> 6 from .rcmod import *
7 from .utils import *
8 from .palettes import *
C:\Users\...\Anaconda2\lib\site-packages\seaborn\rcmod.py in <module>()
6 import matplotlib as mpl
7
----> 8 from . import palettes, _orig_rc_params
9
10
C:\Users\...\Anaconda2\lib\site-packages\seaborn\palettes.py in <module>()
10 from .external.six.moves import range
11
---> 12 from .utils import desaturate, set_hls_values, get_color_cycle
13 from .xkcd_rgb import xkcd_rgb
14 from .crayons import crayons
C:\Users\...\Anaconda2\lib\site-packages\seaborn\utils.py in <module>()
6
7 import numpy as np
----> 8 from scipy import stats
9 import pandas as pd
10 import matplotlib as mpl
C:\Users\...\Anaconda2\lib\site-packages\scipy\stats\__init__.py in <module>()
342 from __future__ import division, print_function, absolute_import
343
--> 344 from .stats import *
345 from .distributions import *
346 from .morestats import *
C:\Users\...\Anaconda2\lib\site-packages\scipy\stats\stats.py in <module>()
171 from scipy._lib._version import NumpyVersion
172 from numpy import array, asarray, ma, zeros
--> 173 import scipy.special as special
174 import scipy.linalg as linalg
175 import numpy as np
C:\Users\...\Anaconda2\lib\site-packages\scipy\special\__init__.py in <module>()
636 from ._ufuncs import *
637
--> 638 from .basic import *
639 from . import specfun
640 from . import orthogonal
C:\Users\...\Anaconda2\lib\site-packages\scipy\special\basic.py in <module>()
13 where, mgrid, sin, place, issubdtype, extract,
14 less, inexact, nan, zeros, atleast_1d, sinc)
---> 15 from ._ufuncs import (ellipkm1, mathieu_a, mathieu_b, iv, jv, gamma,
16 psi, _zeta, hankel1, hankel2, yv, kv, _gammaln,
17 ndtri, errprint, poch, binom, hyp0f1)
ImportError: cannot import name ellipkm1
答案 0 :(得分:0)
我在导入seaborn时遇到了同样的问题,我只是检查它是否安装在我的Python发行版上并且它不是。在我的情况下,我有Anaconda,用于我使用的安装:
conda install seaborn
在进口seaborn之前你还必须进口辛辣包装:
import scipy as sp