Why my python do not work with seaborn - python-3.x

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)
I just copy the example from the documention,but I get such error,I have try to change the enviroment such in shell to run it .But fail too.
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

Can you tell me the numpy and statsmodel version that you use ?
You can try the following:
1) Update the statsmodel package using
pip install -U statsmodels
2) can you try to run the following and let me if it works?
sns.distplot(x, bins=50, kde=False)
plt.show()
P.S: your code works for me using: numpy: 1.11.3, scipy: 0.18.1, statsmodels: 0.6.1

May be the version is not up to date.so follow the below command it worked.
sudo pip install --upgrade seaborn

This may solve your error:
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)

Related

AttributeError: module 'numpy.random' has no attribute 'BitGenerator' in python 3.8.10

I'm trying to import the xarray module into python 3.8.10 but I get this error:
AttributeError: module 'numpy.random' has no attribute 'BitGenerator'
In order to allow you to reproduce the error: First of all, I created a new environment with conda and by importing at the same time the modules I need (to avoid the problems of incompatible dependencies) :
conda create -n Myenv Python=3.8 matplotlib numpy time xarray netCDF4 termcolor
Then, I try to import in ipython3 all modules I need to run my code:
import matplotlib as mpl
mpl.use('agg')
import numpy as np
import os
import time
import glob
import sys
from datetime import datetime,date,timedelta
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
import matplotlib.colors as colors
# from operator import itemgetter
from netCDF4 import Dataset
from mpl_toolkits.basemap import Basemap, shiftgrid
from termcolor import colored
import xarray as xr
and, at this moment, I get the error...
I searched the documentation to see if the BitGenerator Attribute exists in my version of numpy (1.22.3), and it does. So I don't understand why this error occurs.
Someone can help me to understand please ?
Thank u !
If you want more informations about my environnement, I can provide.
I solved mine with pip install --upgrade numpy

'gensim' is not defined even though it shows in the virtualenv packages

I use virtualenv in Python. I use gensim in a script. I get this error
name 'gensim' is not defined
I tried to install genism using pip and conda. I ended up updating conda packages after some suggested solution .
I see there is genism 3.8 after reunnig pip list, but I still have the error !. Could you please tell me what to do
P.S. I take input from a html form in a Flask function. Inside the function, I call the script that has genism. The program show the forms input buttons . After clicking the submit buton, I get the error message.
import re
import numpy as np
import pandas as pd
from pprint import pprint
#database
import db
from db import *
# Gensim
import gensim
import gensim.corpora as corpora
from gensim.utils import simple_preprocess
from gensim.models import CoherenceModel
from gensim.parsing.preprocessing import preprocess_string, strip_punctuation, strip_numeric
# spacy for lemmatization
import spacy
# Plotting tools
import pyLDAvis
import pyLDAvis.gensim # don't skip this
import matplotlib.pyplot as plt
#matplotlib inline
from conn import *
from functions import *
# Enable logging for gensim - optional
import logging
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.ERROR)
import warnings
warnings.filterwarnings("ignore",category=DeprecationWarning)
Thanks in advance

Is there any way to make the libraries from python to work?

I have been struggling for several hours to import keras and tensorflow, but I am unable to import them.
import os
import random
import sys
# Package
import glob
import tensorflow as tf
import keras
import IPython.display as ipd
import librosa
import librosa.display
import matplotlib.pyplot as plt
import numpy as np
Also, when I try to import something, I am unable to do that. Could someone help me out ?
Thank you !
These are the errors I got:
Original exception was:
Traceback (most recent call last):
File "/home/vlad/speech_recognition/emotionrecognition.py", line 8, in <module>
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'

Impossible to import pandas ! "Is this due to the latest release?"

I'm trying to import pandas and I'm facing some issues
import numpy as np
import multiprocessing as mp
import pandas as pd
result:
C:\Anaconda\lib\site-packages\pandas\core\indexes\base.py in <module>
57 import pandas.core.sorting as sorting
58 from pandas.io.formats.printing import pprint_thing
---> 59 from pandas.core.ops import _comp_method_OBJECT_ARRAY
60 from pandas.core import strings, accessor
61 from pandas.core.config import get_option
ImportError: cannot import name 'ops'
OR
AttributeError: module 'pandas' has no attribute 'core'
Please try the following step and restart the jupyter notebook:
conda upgrade --all
If it is still showing the same error, try downgrading the pandas version:
pip install pandas==0.22.0
Hope this helps.

ModuleNotFoundError: no module named 'scipy'

Hi I am bit of newby tinkering around with some machine learning, and I am getting an error in the python shell for scipy. I did a pip install for scipy in the windows command prompt and there are some odd looking errors when pip attempts to install. This is the simple little code I am using, any ideas to try for the scipy error?
import pandas as pd
import math
import numpy as np
import scipy
from sklearn import preprocessing, cross_validation, svm
from sklearn.linear_model import LinearRegression
df = pd.read_csv('C:\\Users\\bbartling\\Documents\\Python\\test_SP data\\testElectData.csv')
df = df[['kWhDay','CDDbase55',]]
print(df.head())
# forecast_col = 'kWhDay'
X = np.array(df.drop(['kWhDay'],1))
y = np.array(df.drop(['CDDbase55'],1))
I figured this out on how to install python modules thru wheels. Good U tube video to make it work
https://www.youtube.com/watch?v=YXIlclFQZVU

Resources