Series Attributes
Read the facts about a Series — shape, size, dtype, name, ndim, is_unique, hasnans, empty — and summarise it with info().
Before you analyse a column, you want quick facts about it: how many values, what type, are there missing values, are the labels unique? Attributes answer these questions instantly, without changing the data.
Definition
An attribute is a property stored on an object that you read without parentheses (
s.shape), while a method is a function you call with parentheses (s.count()). Series attributes describe the Series' structure and contents — its size, type, name and labels.
- Without parentheses —
s.dtype✅,s.dtype()❌ (TypeError: ... object is not callable). - Describe, not change — reading an attribute never modifies the Series (a few, like
nameandindex, can be assigned).
Syntax
python
s.shape s.size s.ndim s.dtype
s.name s.index s.values s.is_unique
s.hasnans s.empty s.nbytes s.is_monotonic_increasing
s.info() len(s) s.count() # helpers (methods / built-ins)| Attribute | Returns | Meaning |
|---|---|---|
shape | tuple (n,) | number of elements, as a 1-tuple |
size | int | total number of elements (including NaN) |
ndim | int | number of dimensions — always 1 for a Series |
dtype | dtype | the data type of the values |
name | any / None | the Series' name (assignable) |
index | Index | the labels (assignable as a whole) |
values | array | the data (prefer .to_numpy()) |
is_unique | bool | True if all values are different |
hasnans | bool | True if there is at least one missing value |
empty | bool | True if the Series has no elements |
nbytes | int | bytes used by the values |
is_monotonic_increasing | bool | True if values never decrease |
| Helper | Meaning |
|---|---|
len(s) | number of elements (same as size) |
s.count() | number of non-missing elements |
s.info() | printed summary: index type, name, non-null count, dtype, memory |
Example — all the basic attributes
python
import pandas as pd
runs = pd.Series([45, 78, None, 101, 33],
index=["Rohit", "Virat", "Gill", "Pant", "Hardik"],
name="runs")
print(runs)
print("shape :", runs.shape)
print("size :", runs.size)
print("len :", len(runs))
print("ndim :", runs.ndim)
print("dtype :", runs.dtype)
print("name :", runs.name)
print("is_unique:", runs.is_unique)
print("hasnans :", runs.hasnans)
print("empty :", runs.empty)
print("count() :", runs.count())
print("nbytes :", runs.nbytes)
print("index :", runs.index)text
Rohit 45.0
Virat 78.0
Gill NaN
Pant 101.0
Hardik 33.0
Name: runs, dtype: float64
shape : (5,)
size : 5
len : 5
ndim : 1
dtype : float64
name : runs
is_unique: True
hasnans : True
empty : False
count() : 4
nbytes : 40
index : Index(['Rohit', 'Virat', 'Gill', 'Pant', 'Hardik'], dtype='str')How it works:
shapeis(5,)— a tuple with one number because a Series has one dimension.sizeandlencount all 5 slots, whilecount()counts only the 4 non-missing values.size - count()= number of missing values.- Gill's
NonebecameNaN, sodtypeisfloat64andhasnansisTrue. nbytesis 40 because 5 float64 values × 8 bytes each = 40.- The index holds text labels, so it shows
dtype='str'.
Example — is_unique checks values, not labels
python
teams = pd.Series(["MI", "CSK", "MI", "RCB"])
print(teams.is_unique, teams.index.is_unique, teams.dtype)text
False True str"MI" appears twice, so the values are not unique. The index 0–3 is unique — check it with s.index.is_unique.
Example — info()
python
runs.info()text
<class 'pandas.Series'>
Index: 5 entries, Rohit to Hardik
Series name: runs
Non-Null Count Dtype
-------------- -----
4 non-null float64
dtypes: float64(1)
memory usage: 80.0+ bytesHow it works: info() prints (and returns None) a summary: the class, the index range (Rohit to Hardik), the name, how many values are not missing, the dtype, and memory used. With a default index it would say RangeIndex: 5 entries, 0 to 4. The + in 80.0+ means "at least" — text labels can use more memory than shown.
Example — setting name and renaming
python
r = runs.rename("runs_2024") # returns a NEW Series with a new name
print(r.name, runs.name)
runs.name = "score" # assign directly
print(runs.name)text
runs_2024 runs
scoreCommon mistakes
- ❌
s.shape()ors.dtype(). ✅ Attributes have no parentheses:s.shape,s.dtype. - ❌ Using
sizeto count real data. ✅sizeincludesNaN; usecount()for non-missing values. - ❌ Thinking
is_uniquechecks the labels. ✅ It checks the values; uses.index.is_uniquefor labels. - ❌
x = s.info()and then usingx. ✅info()prints and returnsNone.
Interview tip
Q: How do you count missing values in a Series?
A: s.isna().sum() — or s.size - s.count(). Use s.hasnans for a quick yes/no check.
Key points to remember
- Attributes are read without parentheses (s.shape); methods need them (s.count()).
- shape is (n,), ndim is always 1, size and len() count every element including NaN.
- count() counts only non-missing values, so size - count() = number of missing values.
- dtype tells the value type; name is the Series' label and becomes a column name in a DataFrame.
- is_unique checks the values; s.index.is_unique checks the labels.
- hasnans is True if any value is missing; empty is True if there are no elements.
- info() prints a summary (index, name, non-null count, dtype, memory) and returns None.
Try it yourself
Inspect a Series with attributes
info() and is_unique
Practice: health-check a column
Revision Flashcards
Tap a card to flip it and see the answer.
