0
0
Pandasdata~15 mins

shape for dimensions in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding DataFrame Shape for Dimensions
📖 Scenario: Imagine you work in a small bookstore. You have a list of books with details like title, author, and price. You want to understand how many books you have and how many details are recorded for each book.
🎯 Goal: You will create a pandas DataFrame with book details and then find out its shape, which tells you the number of rows and columns.
📋 What You'll Learn
Create a pandas DataFrame with exact book data
Create a variable to store the DataFrame shape
Use the shape attribute to get dimensions
Print the shape to see rows and columns
💡 Why This Matters
🌍 Real World
Knowing the shape of data helps you understand how much information you have and how it is organized, which is important before analysis.
💼 Career
Data scientists and analysts often check data dimensions to plan cleaning, visualization, and modeling steps.
Progress0 / 4 steps
1
Create the DataFrame with book details
Import pandas as pd and create a DataFrame called books with these exact entries: columns 'Title', 'Author', 'Price' and rows: 'The Alchemist', 'Paulo Coelho', 10.99, '1984', 'George Orwell', 8.99, 'Python 101', 'Michael Driscoll', 15.50.
Pandas
Need a hint?

Use pd.DataFrame with a dictionary where keys are column names and values are lists of column data.

2
Create a variable to store the DataFrame shape
Create a variable called dimensions and set it to the shape of the books DataFrame using the shape attribute.
Pandas
Need a hint?

Use books.shape to get a tuple with rows and columns.

3
Extract number of rows and columns
Create two variables called num_rows and num_columns. Set num_rows to the first value of dimensions and num_columns to the second value of dimensions.
Pandas
Need a hint?

The shape attribute returns a tuple: first is rows, second is columns.

4
Print the number of rows and columns
Print the values of num_rows and num_columns separated by a space.
Pandas
Need a hint?

Use print(num_rows, num_columns) to show the shape.