Reputation: 3
I am trying to create a histogram using ggplot, this is my code:
data = pd.read_csv('Weather_not_tidy.csv')
data = data.rename(columns={'Temp2009': '2009', 'Temp2010': '2010'})
tidyData = pd.melt(data2, value_vars=['2009', "2010"], id_vars=['month', 'day', 'hour_of_day'],
var_name='year', value_name='temperature')
tidyData
month day hour_of_day year temperature
0 Jan 1 12 2009 -0.9
1 Jan 2 12 2009 -2.2
2 Jan 3 12 2009 4.2
3 Jan 4 12 2009 -4.7
4 Jan 5 12 2009 -7.8
... ... ... ... ... ...
725 Dec 27 12 2010 -6.8
726 Dec 28 12 2010 -11.0
727 Dec 29 12 2010 -10.6
728 Dec 30 12 2010 -3.0
729 Dec 31 12 2010 -2.7
730 rows × 5 columns
plot = (
ggplot(tidyData, aes(x='temperature', fill='year'))
+ geom_histogram(data=tidyData.loc[tidyData['year']=='2009'], alpha=0.6, bins=10)
)
plot
and I keep getting this error:
AttributeError Traceback (most recent call last)
File ~/anaconda3/envs/MVE080/lib/python3.11/site-packages/IPython/core/formatters.py:711, in PlainTextFormatter.__call__(self, obj)
704 stream = StringIO()
705 printer = pretty.RepresentationPrinter(stream, self.verbose,
706 self.max_width, self.newline,
707 max_seq_length=self.max_seq_length,
708 singleton_pprinters=self.singleton_printers,
709 type_pprinters=self.type_printers,
710 deferred_pprinters=self.deferred_printers)
--> 711 printer.pretty(obj)
712 printer.flush()
713 return stream.getvalue()
File ~/anaconda3/envs/MVE080/lib/python3.11/site-packages/IPython/lib/pretty.py:419, in RepresentationPrinter.pretty(self, obj)
408 return meth(obj, self, cycle)
409 if (
410 cls is not object
411 # check if cls defines __repr__
(...)
417 and callable(_safe_getattr(cls, "__repr__", None))
418 ):
--> 419 return _repr_pprint(obj, self, cycle)
421 return _default_pprint(obj, self, cycle)
422 finally:
...
86 return (
---> 87 trans.dataspace_is_numerical and tname not in linear_transforms
88 )
AttributeError: 'identity_trans' object has no attribute 'dataspace_is_numerical'
I have access to a correct solution to this exercise and it still gives me the exact same error! I am using vscode on Ubuntu, Python 3.11.10 and am using a conda environment with the following dependencies:
name: MVE080
dependencies:
- python=3.11
- plotnine=0.12
- numpy=1.26
- pandas=2.1
- pip=23.1
- pip:
- geopandas
I was expecting to see a histogram with temperature from -10 to 10 on the x axis and the count on the y axis! :(
Upvotes: 0
Views: 52
Reputation: 1
I don't think you posted enough info to solve this problem, but that error means that somewhere in the code there is something called identity_trans and that somewhere in the code you are trying to access an attribute of that object that is not an attribute of that object.
I would look for identity_trans in the code and see where it's trying to reference dataspace_is_numerical as a start.
You posted some of your code but you need to show the part of the code that has dataspace_is_numerical in it for us to really help you.
Edit based on the log I think the problem is probably with pretty.py which is not your program but something that you installed to run with your program I think, perhaps reinstalling that could help.
Upvotes: 0