Skip to content
Exercises · Q4

Q.What do you understand by the size of

(i) a Series,
(ii) a DataFrame?
Puducherry CbseNCERTSubjective· 2mImportance★★★★★
32% · 12/38 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

The size attribute returns the total number of elements in a pandas object — for a Series it's the number of rows, and for a DataFrame it's rows × columns.

In pandas, the size attribute is a quick way to get the total count of elements in a data structure. It's not the same as shape (which gives dimensions) or len() (which gives only the row count). The key idea is that size flattens the structure into a single number: every cell counts.

(i) Size of a Series

A Series is a one-dimensional labelled array. Its size is simply the number of elements (rows) it contains. For example:

import pandas as pd
s = pd.Series([10, 20, 30, 40])
print(s.size)   # Output: 4

If the Series has missing values (NaN), those still count as elements — size counts the total number of positions, not just non-null values. Use count() if you want only non-null entries.

Tip

For a Series, size is equivalent to len(s) and to s.shape[0]. All three give the same result because a Series has only one dimension.

(ii) Size of a DataFrame

A DataFrame is a two-dimensional labelled data structure (rows and columns). Its size is the total number of cells: number of rows × number of columns. For instance:

import pandas as pd
df = pd.DataFrame({'A': [1, 2], 'B': [3, 4], 'C': [5, 6]})
print(df.size)   # Output: 6  (2 rows × 3 columns) …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.