We wish to get the number of rows and / or the number of columns of a data frame.
We wish to obtain both the number of rows and number of columns of a data frame.
df.shape
Here is how this works:
.shape
attribute which returns the number or rows and number of columns of the data frame (as a Tuple
).df
had 100 rows and 10 columns, df.shape
would return (100, 10)
.We wish to obtain the number of rows of a data frame.
len(df)
Here is how this works:
df
to the function len()
.len()
returns the number of rows of the data frame (as an integer).We wish to obtain the number of columns of a data frame.
len(df.columns)
Here is how this works:
We obtain the number of columns of a data frame by using len()
to count the number of column names returned by df.columns
.