LambdaLab
Informatics Practices · Class 12 · Python Pandas · Series
PandasSeries⏱️ 6 min read

Series Attributes

Every Series carries built-in attributes that describe it — its labels, its values, its type, its size, and more. They're facts about the Series, so you read them without brackets.

1Click through the attributes

Here's a sample Series with a name and one missing value. Click any attribute to see what it returns.

Attribute inspector

Attributes describe a Series (no brackets — they're not functions). Click one to see what it returns.

Math_Scores
a95.0
bNaN
c72.0
d91.0
dtype: float64
# the labels
s.index
Index(['a', 'b', 'c', 'd'], dtype='object')

2The nine key attributes

  • index — the labels of the Series.
  • values — the data, returned as a NumPy array.
  • dtype — the data type of the values (e.g. int64, float64, object).
  • shape — the dimensions as a tuple; always (n,) for a Series.
  • ndim — number of dimensions; always 1.
  • size — the total number of elements.
  • name— the Series' optional name.
  • hasnansTrue if it contains any NaN.
  • emptyTrue if the Series has no elements.

3See them all at once

Run this and match each printout to the widget above. Watch the dtype: because one value is NaN, the whole Series is float64.

attributes.py
Watch Out
Attributes take no brackets: it's s.size, not s.size(). Adding () tries to call it like a function and errors. (Methods like head() do need brackets — the bracket is the giveaway.)
Quick Check

Which attribute tells you whether a Series contains any missing values?

Quick Check

What is s.ndim for any Series?