1

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?

1 Answer 1

1

You probably confused it with numpy.ndarray.itemsize in .

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.