Pandas: Count the number of rows and columns of the DataFrame
4. Count Rows and Columns
Write a Pandas program to count the number of rows and columns of the DataFrame (movies_metadata.csv file).
Sample Solution:
Python Code :
import pandas as pd
df = pd.read_csv('movies_metadata.csv')
result = df.shape
print("Number of rows and columns of the DataFrame:")
print(result)
Sample Output:
Number of rows and columns of the DataFrame: (50, 24)
For more Practice: Solve these Related Problems:
- Write a Pandas program to load movies_metadata.csv and output the number of rows and columns as a tuple.
- Write a Pandas program to compute the shape of movies_metadata.csv and print a descriptive message with the counts.
- Write a Pandas program to load movies_metadata.csv and verify the dimensions by comparing len(df.index) and len(df.columns).
- Write a Pandas program to calculate and display the total number of cells in movies_metadata.csv by multiplying rows and columns.
Python-Pandas Code Editor:
Sample Table:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Pandas program to get the details of the third movie of the DataFrame (movies_metadata.csv file).
Next: Write a Pandas program to get the details of the columns title and genres of the DataFrame.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.