NameError Traceback (most recent call last)
C:\Users\HTCOMP~1\AppData\Local\Temp/ipykernel_6676/988855770.py in <module>
----> 1 sns.distplot(data_no_mv['body'])
NameError: name 'sns' is not defined
sns usually represents the seaborn library, so you might need to add import seaborn as sns to the beginning of your code. You might already have done this and something else might be wrong, but it is hard to tell without the code.
Related
I have the following code:
import matplotlib.pyplot as plt
plt.cm.set_cmap("Blues")
This gives me an error:
Traceback (most recent call last):
File ".\lorenz_explorer.py", line 12, in <module>
plt.cm.set_cmap("Blues")
AttributeError: module 'matplotlib.cm' has no attribute 'set_cmap'
My matplotlib version is 3.3.1, and the function certainly exists in the documentation for 3.3.1: Link
Then am I doing something wrong or is this a bug? Do I need to import matplotlib.cm separately or something along those lines?
As the documentation link you provide shows, the name of the function is matplotlib.pyplot.set_cmap, not matplotlib.pyplot.cm.set_cmap. So you can call it with plt.set_cmap("Blues").
In other words, the function is not part of the cm library, which is somewhat counter-intuitive.
I am trying to use pandas for the first time and I have copied a very simple program
import pandas as pd
series1 = pd.Series([1,2,3,4])
print(series1)
The issue I am having is that when I try and run the program I am getting the following error
Traceback (most recent call last):
File "C:\Users\faintr\AppData\Local\Programs\Python\Python38-32\pandas.py", line 1, in <module>
import pandas as pd
File "C:\Users\faintr\AppData\Local\Programs\Python\Python38-32\pandas.py", line 2, in <module>
series1 = pd.Series([1,2,3,4])
AttributeError: partially initialized module 'pandas' has no attribute 'Series' (most likely due to a circular import)
Pandas version(1.14.0) is installed.
I have looked into circular imports and whilst I think I understand the concept if this is the cause I do not know how to fix it. I have tried downgrading pandas to an earlier version with no look
Can anyone help please
I am trying the function on this doc
import matplotlib.pyplot as plt
plt.colors()
got this error
--------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-1-e2c1adbcc48e> in <module>
1 import matplotlib.pyplot as plt
----> 2 plt.colors()
AttributeError: module 'matplotlib.pyplot' has no attribute 'colors'
the doc says
The colors function was deprecated in version 2.1.
without providing a substitute.
is there a substitute for matplotlib.pyplot.colors?
To be more precise here: No, there is no substitude for matplotlib.pyplot.colors because its only purpose was to allow users to get help via help(plt.colors). It was considered more harmful to confuse users by the presence of this function, which doesn't do anything, than it to be useful to let them get help on colors via pyplot. If you want to get help on colors now, you may still type
help(matplotlib.colors)
though that is a bit more lengthy.
I'm following the tutorial plotly timeseries, here. I've also amended the code to allow for offline charts in Jupyter, here.
I'm trying to plot a timeseries in Jupyter Notebook. I get the following error.
AttributeError: module 'plotly.plotly' has no attribute 'offline'
As far as I can see I've carried out all the instructions but can't get it to work with the method they suggest.
import plotly.plotly as py
import plotly.graph_objs as go
py.offline.init_notebook_mode()
data = [go.Scatter(x=dataload.date, y=dataload.spend)]
py.offline.iplot(data)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-14-c9b2e8d8907c> in <module>()
2 import plotly.graph_objs as go
3
----> 4 py.offline.init_notebook_mode()
5
6 data = [go.Scatter(x=dataload.date, y=dataload.spend)]
AttributeError: module 'plotly.plotly' has no attribute 'offline'
Does anyone have a suggestion to why I might be getting this error, could it be a local setup issue?
Just use:
import plotly
plotly.offline.init_notebook_mode()
don't use: import plotly.plotly as py
You are referring different documentation. Use https://plot.ly/python/getting-started/#initialization-for-offline-plotting
Here it also provides more information regarding how to use help function.
For tutorial in offline mode: https://github.com/SayaliSonawane/Plotly_Offline_Python
from sklearn.datasets import fetch_mldata
mnist = fetch_mldata('MNIST original', data_home=custom_data_home)
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
mnist = fetch_mldata('MNIST original', data_home=custom_data_home)
NameError: name 'custom_data_home' is not defined
i am getting NameError, i searched in net for solutions, i didn't get any relevant answers.
i even tries installing "custom_data_home" using easy_install . it says it could not find.
pls help me on this.
I don't know anything about sklearn, but it looks like you are trying to use the example from this page: http://scikit-learn.org/stable/datasets/mldata.html
In that example custom_data_home is a variable containing the path to where you want the data stored. If you leave it off it says it should default to just data.
Basically in your script you have not defined custom_data_home. That is what NameError is telling you.
If you are going to use a variable, like custom_data_home you have to define it in some way. Your script doesn't know what custom_data_home is.
custom_data_home = '/path/to/my/data'
mnist = fetch_mldata('MNIST original', data_home=custom_data_home)
That should work.