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 dictionary in pandas?
Use
pd.DataFrame() and pass the dictionary as an argument. Keys become column names, and values become the column data.Click to reveal answer
intermediate
What happens if dictionary values have different lengths when creating a DataFrame?
pandas will raise a
ValueError because all columns must have the same number of elements.Click to reveal answer
beginner
Example: Create a DataFrame from
{'Name': ['Alice', 'Bob'], 'Age': [25, 30]}. What will be the columns?The DataFrame will have two columns: Name and Age. Each row corresponds to a person with their name and age.
Click to reveal answer
intermediate
Can dictionary keys be used as row labels (index) when creating a DataFrame?
No, dictionary keys become column names. To set row labels, use the
index parameter separately.Click to reveal answer
What does each key in the dictionary represent when creating a DataFrame?
✗ Incorrect
Each key in the dictionary becomes a column name in the DataFrame.
Which pandas function is used to create a DataFrame from a dictionary?
✗ Incorrect
pd.DataFrame() creates a DataFrame from various data structures including dictionaries.What error occurs if dictionary values have different lengths when creating a DataFrame?
✗ Incorrect
pandas raises a
ValueError because columns must have the same length.If you want to set custom row labels when creating a DataFrame from a dictionary, which parameter do you use?
✗ Incorrect
The
index parameter sets custom row labels.What will be the output columns for
{'City': ['NY', 'LA'], 'Population': [8, 4]}?✗ Incorrect
Keys become columns: 'City' and 'Population'.
Explain how to create a pandas DataFrame from a dictionary and what the dictionary keys and values represent.
Think about how a table is formed from columns and rows.
You got /4 concepts.
Describe what happens if the dictionary values have different lengths when creating a DataFrame.
Consider the shape of a table and why it must be consistent.
You got /3 concepts.