0
0
Pandasdata~30 mins

DataFrame as labeled two-dimensional table in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
DataFrame as labeled two-dimensional table
📖 Scenario: You work in a small bookstore. You want to organize your book sales data in a clear table format to analyze it easily.
🎯 Goal: Create a pandas DataFrame to represent book sales with labels for rows and columns. Then display the table.
📋 What You'll Learn
Use pandas to create a DataFrame
Include book titles as row labels
Include sales data as columns
Print the DataFrame to show the table
💡 Why This Matters
🌍 Real World
Organizing sales or inventory data in tables helps businesses track performance clearly.
💼 Career
Data analysts and scientists often use pandas DataFrames to manage and analyze labeled data efficiently.
Progress0 / 4 steps
1
Create the sales data dictionary
Create a dictionary called sales_data with these exact entries: 'Title' as a list of 'Book A', 'Book B', 'Book C'; 'Copies Sold' as a list of 150, 200, 120; and 'Revenue' as a list of 3000, 5000, 2400.
Pandas
Need a hint?

Use a dictionary with keys 'Title', 'Copies Sold', and 'Revenue'. Each key should have a list of values.

2
Import pandas and create DataFrame
Import pandas as pd. Then create a DataFrame called df from the sales_data dictionary.
Pandas
Need a hint?

Use import pandas as pd and then pd.DataFrame() with the dictionary.

3
Set the 'Title' column as row labels
Use the set_index method on df to set the 'Title' column as the index (row labels). Assign the result back to df.
Pandas
Need a hint?

Use df.set_index('Title') and assign it back to df.

4
Print the DataFrame
Print the DataFrame df to display the labeled two-dimensional table.
Pandas
Need a hint?

Use print(df) to show the table.