Challenge - 5 Problems
DataFrame Structure Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this DataFrame index query?
Given the DataFrame
df below, what will df.index return?Data Analysis Python
import pandas as pd df = pd.DataFrame({ 'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, 30, 35] }) result = df.index
Attempts:
2 left
💡 Hint
The index represents the row labels, which by default are numbers starting at zero.
✗ Incorrect
By default, pandas assigns a RangeIndex starting at 0 for rows if no index is specified.
❓ query_result
intermediate2:00remaining
What does
df.columns return for this DataFrame?Given the DataFrame
df below, what will df.columns output?Data Analysis Python
import pandas as pd df = pd.DataFrame({ 'City': ['Paris', 'London', 'Berlin'], 'Population': [2148000, 8982000, 3769000] }) result = df.columns
Attempts:
2 left
💡 Hint
Columns represent the names of the data fields in the DataFrame.
✗ Incorrect
The columns attribute returns the labels of the columns as an Index object.
❓ query_result
advanced2:00remaining
What is the output of
df.values for this DataFrame?Given the DataFrame
df below, what will df.values return?Data Analysis Python
import pandas as pd df = pd.DataFrame({ 'Product': ['Pen', 'Pencil'], 'Price': [1.5, 0.5] }) result = df.values
Attempts:
2 left
💡 Hint
Values returns the data as a 2D array without the index or columns labels.
✗ Incorrect
df.values returns the underlying data as a numpy array of lists representing rows.
🧠 Conceptual
advanced2:00remaining
Which statement about DataFrame structure is true?
Select the correct statement about the structure of a pandas DataFrame.
Attempts:
2 left
💡 Hint
Think about what index and columns represent in a table.
✗ Incorrect
The index labels the rows, and columns label the columns. Values are the data inside.
🔧 Debug
expert2:00remaining
Why does this code raise an error when accessing DataFrame values?
Consider this code snippet:
import pandas as pd
df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
result = df.values[0]['A']
Why does this raise an error?Attempts:
2 left
💡 Hint
Check the type of object returned by df.values and how it can be indexed.
✗ Incorrect
df.values returns a numpy array of the data, so indexing by string like ['A'] is invalid.