Recall & Review
beginner
What is a DataFrame in pandas?
A DataFrame is a table-like data structure in pandas that stores data in rows and columns, similar to a spreadsheet or SQL table.
Click to reveal answer
beginner
How do you create a DataFrame from a list of dictionaries in pandas?
Use the pandas function
pd.DataFrame() and pass the list of dictionaries as the argument. Each dictionary becomes a row, and keys become column names.Click to reveal answer
intermediate
What happens if dictionaries in the list have different keys when creating a DataFrame?
pandas fills missing values with
NaN for keys that are not present in some dictionaries, so the DataFrame columns include all keys from all dictionaries.Click to reveal answer
beginner
Example: Create a DataFrame from this list of dictionaries:<br>
[{'name': 'Alice', 'age': 25}, {'name': 'Bob', 'age': 30}]Code:<br><code>import pandas as pd
people = [{'name': 'Alice', 'age': 25}, {'name': 'Bob', 'age': 30}]
df = pd.DataFrame(people)
print(df)</code><br>Output:<br><code> name age
0 Alice 25
1 Bob 30</code>Click to reveal answer
beginner
Why is creating a DataFrame from a list of dictionaries useful in real life?
It lets you easily convert structured data from sources like JSON files, APIs, or user input into a table format for analysis and visualization.
Click to reveal answer
What does each dictionary in a list represent when creating a DataFrame from it?
✗ Incorrect
Each dictionary corresponds to one row, with keys as column names.
If some dictionaries lack certain keys, what does pandas put in those DataFrame cells?
✗ Incorrect
pandas uses NaN to represent missing values in the DataFrame.
Which pandas function creates a DataFrame from a list of dictionaries?
✗ Incorrect
pd.DataFrame() is used to create DataFrames from various data structures including lists of dictionaries.
What type of data structure is a DataFrame similar to?
✗ Incorrect
A DataFrame is like a table with rows and columns.
Which of these is a valid way to create a DataFrame from a list of dictionaries named 'data'?
✗ Incorrect
pd.DataFrame(data) directly converts a list of dictionaries into a DataFrame.
Explain how to create a pandas DataFrame from a list of dictionaries and what happens if some dictionaries have missing keys.
Think about rows, columns, and missing data handling.
You got /4 concepts.
Describe a real-life situation where creating a DataFrame from a list of dictionaries would be helpful.
Consider where you get data in dictionary form.
You got /4 concepts.