0
0
Pandasdata~10 mins

Series vs DataFrame relationship in Pandas - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a pandas Series from a list.

Pandas
import pandas as pd

my_list = [10, 20, 30]
my_series = pd.[1](my_list)
print(my_series)
Drag options to blanks, or click blank then click option'
Aarray
BDataFrame
CSeries
Dlist
Attempts:
3 left
💡 Hint
Common Mistakes
Using DataFrame instead of Series to create a single column.
Trying to use list() which is a Python built-in, not pandas.
2fill in blank
medium

Complete the code to create a DataFrame from two Series.

Pandas
import pandas as pd

s1 = pd.Series([1, 2, 3])
s2 = pd.Series([4, 5, 6])
df = pd.DataFrame({'A': s1, 'B': [1])
print(df)
Drag options to blanks, or click blank then click option'
As1
Bs2
C[4, 5, 6]
Dpd.Series
Attempts:
3 left
💡 Hint
Common Mistakes
Using s1 twice instead of s2 for the second column.
Passing a list instead of a Series for the second column.
3fill in blank
hard

Fix the error in the code to select a column from a DataFrame as a Series.

Pandas
import pandas as pd

df = pd.DataFrame({'X': [7, 8, 9], 'Y': [10, 11, 12]})
col = df[1]['X']
print(type(col))
Drag options to blanks, or click blank then click option'
A['X']
B.iloc
C[['X']]
D.loc
Attempts:
3 left
💡 Hint
Common Mistakes
Using .iloc which selects by position, not label.
Using double brackets which returns a DataFrame, not Series.
4fill in blank
hard

Fill both blanks to create a DataFrame from a dictionary of Series and select a Series column.

Pandas
import pandas as pd

s1 = pd.Series([1, 2, 3])
s2 = pd.Series([4, 5, 6])
df = pd.DataFrame({'A': s1, 'B': s2})
selected = df[1]['[2]']
print(selected)
Drag options to blanks, or click blank then click option'
A.loc
B.iloc
CA
DB
Attempts:
3 left
💡 Hint
Common Mistakes
Using .iloc which selects by position, not label.
Selecting column 'A' instead of 'B'.
5fill in blank
hard

Fill all three blanks to create a DataFrame, add a new Series column, and select it.

Pandas
import pandas as pd

s1 = pd.Series([10, 20, 30])
s2 = pd.Series([40, 50, 60])
df = pd.DataFrame({'X': s1})
df['[1]'] = [2]
df_selected = df[3]['Y']
print(df_selected)
Drag options to blanks, or click blank then click option'
AY
Bs2
C.loc
D.iloc
Attempts:
3 left
💡 Hint
Common Mistakes
Using .iloc instead of .loc for label selection.
Using wrong column name when adding or selecting.