I am new to Python Pandas, and, as part of that, I wanted to create a pandas.Series and print the itemsize of the Series. However, while I was doing that, it returned an attribute error.
Following is my code:
import pandas as pd
data = [1, 2, 3, 4]
s = pd.Series(data)
print(s.itemsize)
This however does not return the itemsize and throws the following error:
Traceback (most recent call last):
File "c:\Users\USER\filename.py", line 32, in <module>
print(s.itemsize)
^^^^^^^^^^
File "C:\Users\USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\generic.py", line 5902, in __getattr__
return object.__getattribute__(self, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Series' object has no attribute 'itemsize'```
What might the reason for this be?
CodePudding user response:
You probably confused it with numpy.ndarray.itemsize
in numpy.
In pandas, it's pandas.Series.dtype.itemsize
:
import pandas as pd
data = [1, 2, 3, 4]
s = pd.Series(data)
Output :
print(s.dtype.itemsize)
#8