How To Get The Dimension Of A DataFrame?


How To Get The Dimension Of A DataFrame?

Table Of Contents:

  1. Syntax To Print Dimension Of Data Frame.
  2. Examples Of Printing Dimension.

(1) Syntax:

property DataFrame.ndim

Description:

  • Return an int representing the number of axes / array dimensions.
  • Return 1 if Series. Otherwise return 2 if DataFrame.

(2) Examples Of Columns :

Example-1

s = pd.Series({'a': 1, 'b': 2, 'c': 3})
s.ndim

Output:

1

Example-2

df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
df

Output:

df.ndim

Output:

2

Leave a Reply

Your email address will not be published. Required fields are marked *