0
0
Pandasdata~15 mins

Creating DataFrame from list of lists in Pandas - Try It Yourself

Choose your learning style9 modes available
Creating DataFrame from list of lists
📖 Scenario: You work in a small store and have a list of daily sales data. Each entry has the product name, quantity sold, and price per item.
🎯 Goal: You will create a pandas DataFrame from this list of lists to organize the sales data in a table format.
📋 What You'll Learn
Use the pandas library
Create a DataFrame from a list of lists
Assign column names to the DataFrame
Print the DataFrame to see the organized data
💡 Why This Matters
🌍 Real World
Stores and businesses often collect sales data in lists or spreadsheets. Organizing this data into tables helps analyze sales and make decisions.
💼 Career
Data scientists and analysts use pandas DataFrames to clean, organize, and analyze data from many sources.
Progress0 / 4 steps
1
Create the sales data list
Create a variable called sales_data that is a list of lists with these exact entries: ["Apple", 10, 0.5], ["Banana", 5, 0.3], and ["Orange", 8, 0.7].
Pandas
Need a hint?

Use square brackets to create a list of lists. Each inner list has three elements: product name, quantity, and price.

2
Import pandas and set column names
Import the pandas library as pd. Then create a list called columns with these exact strings: "Product", "Quantity", and "Price".
Pandas
Need a hint?

Use import pandas as pd to import pandas. Create a list with the column names exactly as shown.

3
Create the DataFrame from the list
Create a pandas DataFrame called df from the sales_data list using the columns list for column names.
Pandas
Need a hint?

Use pd.DataFrame() with the data and columns arguments.

4
Print the DataFrame
Print the DataFrame df to display the organized sales data.
Pandas
Need a hint?

Use print(df) to show the DataFrame.