0
0
Pandasdata~20 mins

Series vs DataFrame relationship in Pandas - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Series vs DataFrame Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
A<class 'list'>
B<class 'pandas.core.frame.DataFrame'>
C<class 'pandas.core.series.Series'>
D<class 'dict'>
Attempts:
2 left
💡 Hint
Accessing a single column from a DataFrame returns a Series.
Predict Output
intermediate
2: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)
A(3,) (3, 1)
B(3, 1) (3,)
C(1, 3) (1, 3)
D(3,) (1, 3)
Attempts:
2 left
💡 Hint
Series shape is one-dimensional, DataFrame shape is two-dimensional.
data_output
advanced
3: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)
A{'A': [1, 2, 3], 'B': [4, 5, 6]}
B
   A  B
0  1  4
1  2  5
2  3  6
C
0    1
1    2
2    3
0    4
1    5
2    6
D
A    1
B    4
A    2
B    5
A    3
B    6
Attempts:
2 left
💡 Hint
Concatenating Series along axis=1 creates columns in a DataFrame.
🧠 Conceptual
advanced
2:00remaining
Relationship between Series and DataFrame
Which statement best describes the relationship between a pandas Series and a DataFrame?
AA Series is a single column of data, and a DataFrame is a collection of Series sharing the same index.
BA Series is a two-dimensional table, and a DataFrame is a one-dimensional array.
CA Series and a DataFrame are completely unrelated data structures in pandas.
DA DataFrame is a single column of data, and a Series is a collection of DataFrames sharing the same index.
Attempts:
2 left
💡 Hint
Think about how columns relate to the whole table.
🔧 Debug
expert
3: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])
ATypeError: Cannot create a Series from a DataFrame column
BNo error, s is a Series with length 3
CKeyError: 'A'
DValueError: Length of passed values is 3, index implies 2
Attempts:
2 left
💡 Hint
Check if the index length matches the data length.