question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sns.kdeplot() || TypeError: slice indices must be integers or None or have an __index__ method

See original GitHub issue

I can’t get kdeplot or distplot to work with my pd.Series (or np.array)

u = np.array([ 3.41959 , 1.79315 , 1.17229 , 1.59909 , 1.27337 , 1.21917 , 2.60591 , 2.0571 , 1.83865 , 1.94869 , 1.65421 , 1.67777 , 1.23781 , 1.46352 , 1.41791 , 2.00387 , 2.51076 , 1.59734 , 1.32982 , 1.89372 , 1.40614 , 1.41747 , 1.34109 , 1.38647 , 1.49432 , 1.05335 , 1.03805 , 1.18631 , 1.06402 , 1.06929 , 1.12031 , 1.07605 , 1.25702 , 1.25158 , 1.06541 , 1.07368 , 1.00559 , 1.00555 , 1.54561 , 1.01144 , 1.79598 , 1.02094 , 1.36236 , 1.6214 , 1.09803 , 1.25866 , 0.987888, 0.993576, 1.25805 , 5.67273 , 1.20665 , 0.985643, 1.07809 , 1.22087 , 1.1201 , 1.0367 , 1.26575 , 1.0295 , 0.993422, 1.08648 , 1.32767 , 1.35376 , 0.98585 , 0.991962, 1.49533 , 1.04997 , 0.995653, 1.13044 , 1.12311 , 1.29017 , 1.6424 , 1.1599 , 1.26453 , 1.0633 , 1.00454 , 1.35529 , 0.990889, 1.19621 , 1.30717 , 1.32321 , 1.5471 , 1.13225 , 1.97847 , 1.17142 , 1.36377 , 2.14062 , 0.996708, 1.03417 , 1.03212 , 1.0082 , 1.06432 , 3.49213 , 4.28245 , 1.00274 , 1.09338 , 1.0156 , 1.13566 , 1.10697 , 1.56438 , 0.96706 ], dtype=float)
Se_u = pd.Series(u)
sns.kdeplot(Se_u)

This is the error I get:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-27-70aaa51b2d69> in <module>()
      4 u = np.array([ 3.41959 , 1.79315 , 1.17229 , 1.59909 , 1.27337 , 1.21917 , 2.60591 , 2.0571 , 1.83865 , 1.94869 , 1.65421 , 1.67777 , 1.23781 , 1.46352 , 1.41791 , 2.00387 , 2.51076 , 1.59734 , 1.32982 , 1.89372 , 1.40614 , 1.41747 , 1.34109 , 1.38647 , 1.49432 , 1.05335 , 1.03805 , 1.18631 , 1.06402 , 1.06929 , 1.12031 , 1.07605 , 1.25702 , 1.25158 , 1.06541 , 1.07368 , 1.00559 , 1.00555 , 1.54561 , 1.01144 , 1.79598 , 1.02094 , 1.36236 , 1.6214 , 1.09803 , 1.25866 , 0.987888, 0.993576, 1.25805 , 5.67273 , 1.20665 , 0.985643, 1.07809 , 1.22087 , 1.1201 , 1.0367 , 1.26575 , 1.0295 , 0.993422, 1.08648 , 1.32767 , 1.35376 , 0.98585 , 0.991962, 1.49533 , 1.04997 , 0.995653, 1.13044 , 1.12311 , 1.29017 , 1.6424 , 1.1599 , 1.26453 , 1.0633 , 1.00454 , 1.35529 , 0.990889, 1.19621 , 1.30717 , 1.32321 , 1.5471 , 1.13225 , 1.97847 , 1.17142 , 1.36377 , 2.14062 , 0.996708, 1.03417 , 1.03212 , 1.0082 , 1.06432 , 3.49213 , 4.28245 , 1.00274 , 1.09338 , 1.0156 , 1.13566 , 1.10697 , 1.56438 , 0.96706 ], dtype=float)
      5 Se_u = pd.Series(u)
----> 6 sns.kdeplot(Se_u)

/Users/jespinoz/anaconda/lib/python3.5/site-packages/seaborn/distributions.py in kdeplot(data, data2, shade, vertical, kernel, bw, gridsize, cut, clip, legend, cumulative, shade_lowest, ax, **kwargs)
    602         ax = _univariate_kdeplot(data, shade, vertical, kernel, bw,
    603                                  gridsize, cut, clip, legend, ax,
--> 604                                  cumulative=cumulative, **kwargs)
    605 
    606     return ax

/Users/jespinoz/anaconda/lib/python3.5/site-packages/seaborn/distributions.py in _univariate_kdeplot(data, shade, vertical, kernel, bw, gridsize, cut, clip, legend, ax, cumulative, **kwargs)
    268         x, y = _statsmodels_univariate_kde(data, kernel, bw,
    269                                            gridsize, cut, clip,
--> 270                                            cumulative=cumulative)
    271     else:
    272         # Fall back to scipy if missing statsmodels

/Users/jespinoz/anaconda/lib/python3.5/site-packages/seaborn/distributions.py in _statsmodels_univariate_kde(data, kernel, bw, gridsize, cut, clip, cumulative)
    326     fft = kernel == "gau"
    327     kde = smnp.KDEUnivariate(data)
--> 328     kde.fit(kernel, bw, fft, gridsize=gridsize, cut=cut, clip=clip)
    329     if cumulative:
    330         grid, y = kde.support, kde.cdf

/Users/jespinoz/anaconda/lib/python3.5/site-packages/statsmodels/nonparametric/kde.py in fit(self, kernel, bw, fft, weights, gridsize, adjust, cut, clip)
    144             density, grid, bw = kdensityfft(endog, kernel=kernel, bw=bw,
    145                     adjust=adjust, weights=weights, gridsize=gridsize,
--> 146                     clip=clip, cut=cut)
    147         else:
    148             density, grid, bw = kdensity(endog, kernel=kernel, bw=bw,

/Users/jespinoz/anaconda/lib/python3.5/site-packages/statsmodels/nonparametric/kde.py in kdensityfft(X, kernel, bw, weights, gridsize, adjust, clip, cut, retgrid)
    504     zstar = silverman_transform(bw, gridsize, RANGE)*y # 3.49 in Silverman
    505                                                    # 3.50 w Gaussian kernel
--> 506     f = revrt(zstar)
    507     if retgrid:
    508         return f, grid, bw

/Users/jespinoz/anaconda/lib/python3.5/site-packages/statsmodels/nonparametric/kdetools.py in revrt(X, m)
     18     if m is None:
     19         m = len(X)
---> 20     y = X[:m/2+1] + np.r_[0,X[m/2+1:],0]*1j
     21     return np.fft.irfft(y)*m
     22 

TypeError: slice indices must be integers or None or have an __index__ method

but this works:

Se_u.plot(kind="kde")

image

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

16reactions
jolespincommented, Jan 25, 2017

Sorry about that @mwaskom I searched around but I didn’t see it.
conda uninstall statsmodels --yes conda install -c taugspurger statsmodels=0.8.0 This fixed everything.

4reactions
TomAugspurgercommented, Apr 14, 2017

statsmodels 0.8.0 is on conda-forge. Install instructions are here, but conda install -c conda-forge statsmodels

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: slice indices must be integers or None or have an ...
The Python TypeError: slice indices must be integers or None or have an index method occurs when we use a non-integer value for...
Read more >
TypeError slice indices must be integers or none or have an ...
The solution to this problem is to use integers while mentioning slicing indices. Let us get into the details.
Read more >
Kaggle TypeError: slice indices must be integers or None or ...
As @ryankdwyer pointed out, it was an issue in the underlying statsmodels implementation which is no longer existent in the 0.8.0 release.
Read more >
Slice indices must be integers or None or have an __index
TypeError: slice indices must be integers or None or have an __index__ method. Indexing lets you uniquely identify all the items in a...
Read more >
[Solved]-Kaggle TypeError: slice indices must be integers or None or ...
[Solved]-Kaggle TypeError: slice indices must be integers or None or have an __index__ method-Pandas,Python ... As @ryankdwyer pointed out, it was an issue...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found