import pandas as pd
import numpy as np
import sklearn
from scipy import stats
import matplotlib.pyplot as plt
import os
import seaborn as sns
sns.set(); np.random.seed(0)
x = np.random.randn(100)
sns.distplot(x)
我只是从文档中复制了这个例子,但是我得到了这样的错误,我试着改变shell中的环境来运行它。但是也失败了。
Traceback (most recent call last):
File "/Users/Betterwittyman/Desktop/job_25/别人的/pdf_model2.py", line 13, in <module>
sns.distplot(x)
TypeError: slice indices must be integers or None or have an __index__ method
你能告诉我你使用的numpy和statsmodel版本吗?
您可以尝试以下方法:
1)使用更新statsmodel包
pip install -U statsmodels
2)你可以尝试运行以下内容,如果有效,请告诉我吗?
sns.distplot(x, bins=50, kde=False)
plt.show()
P.S:你的代码适用于我:numpy:1.11.3,scipy:0.18.1,statsmodels:0.6.1
这可以解决您的错误:
import pandas as pd
import numpy as np
import sklearn
from scipy import stats
import matplotlib.pyplot as plt
import os
import seaborn as sns
sns.set()
np.random.seed(0)
x = np.random.randn(100)
sns.distplot(x)