0
0
Pandasdata~30 mins

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

Choose your learning style9 modes available
Creating DataFrame from list of dictionaries
📖 Scenario: You work in a small bookstore. You have a list of books with their details stored as dictionaries. You want to organize this data into a table to analyze it easily.
🎯 Goal: Create a pandas DataFrame from a list of dictionaries representing books. Then display the DataFrame.
📋 What You'll Learn
Create a list of dictionaries called books with exact entries
Create a pandas DataFrame called df from the books list
Print the DataFrame df to show the table
💡 Why This Matters
🌍 Real World
Organizing data from lists of dictionaries into tables is common in data analysis, such as managing inventory or customer data.
💼 Career
Data scientists and analysts often convert raw data into DataFrames to clean, analyze, and visualize information efficiently.
Progress0 / 4 steps
1
Create the list of dictionaries
Create a list called books with these exact dictionaries:
{'title': 'The Alchemist', 'author': 'Paulo Coelho', 'year': 1988},
{'title': '1984', 'author': 'George Orwell', 'year': 1949},
{'title': 'To Kill a Mockingbird', 'author': 'Harper Lee', 'year': 1960}
Pandas
Need a hint?

Use square brackets [] to create a list. Each book is a dictionary inside the list.

2
Import pandas and create DataFrame
Import the pandas library as pd. Then create a DataFrame called df from the list books using pd.DataFrame(books).
Pandas
Need a hint?

Use import pandas as pd to import pandas. Then use pd.DataFrame() to create the table.

3
Print the DataFrame
Use print(df) to display the DataFrame df.
Pandas
Need a hint?

Use print(df) to see the table of books.

4
Add a filter for books after 1950
Create a new DataFrame called recent_books that contains only the rows from df where the year is greater than 1950. Use df[df['year'] > 1950].
Pandas
Need a hint?

Use df[df['year'] > 1950] to filter rows where year is greater than 1950.