Challenge - 5 Problems
Series vs DataFrame Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of accessing a DataFrame column
What is the output type of the following code snippet?
Pandas
import pandas as pd df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]}) result = type(df['A']) print(result)
Attempts:
2 left
💡 Hint
Accessing a single column from a DataFrame returns a Series.
✗ Incorrect
When you select one column from a DataFrame using df['A'], it returns a Series object representing that column.
❓ Predict Output
intermediate2:00remaining
Shape of a Series vs DataFrame
What is the output of the following code?
Pandas
import pandas as pd s = pd.Series([10, 20, 30]) df = pd.DataFrame({'X': [10, 20, 30]}) print(s.shape, df.shape)
Attempts:
2 left
💡 Hint
Series shape is one-dimensional, DataFrame shape is two-dimensional.
✗ Incorrect
A Series has a shape with one dimension (number of elements), while a DataFrame has two dimensions (rows, columns).
❓ data_output
advanced3:00remaining
Creating a DataFrame from multiple Series
What is the resulting DataFrame when combining these Series?
Pandas
import pandas as pd s1 = pd.Series([1, 2, 3], name='A') s2 = pd.Series([4, 5, 6], name='B') df = pd.concat([s1, s2], axis=1) print(df)
Attempts:
2 left
💡 Hint
Concatenating Series along axis=1 creates columns in a DataFrame.
✗ Incorrect
Using pd.concat with axis=1 stacks Series side by side as columns, forming a DataFrame.
🧠 Conceptual
advanced2:00remaining
Relationship between Series and DataFrame
Which statement best describes the relationship between a pandas Series and a DataFrame?
Attempts:
2 left
💡 Hint
Think about how columns relate to the whole table.
✗ Incorrect
A DataFrame is like a table made of multiple Series (columns) that share the same index (row labels).
🔧 Debug
expert3:00remaining
Error when converting DataFrame column to Series
What error does the following code produce?
Pandas
import pandas as pd df = pd.DataFrame({'A': [1, 2, 3]}) s = pd.Series(df['A'], index=[0, 1])
Attempts:
2 left
💡 Hint
Check if the index length matches the data length.
✗ Incorrect
The error occurs because the Series constructor expects the index length to match the data length. Here, data has length 3 but index has length 2.