Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
We use pd.Series() to create a Series from a list.
2fill in blank
mediumComplete 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'
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.
✗ Incorrect
To create a DataFrame with two columns, pass both Series as values in the dictionary.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .iloc which selects by position, not label.
Using double brackets which returns a DataFrame, not Series.
✗ Incorrect
Using .loc with the column label selects a Series. Using double brackets returns a DataFrame.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .iloc which selects by position, not label.
Selecting column 'A' instead of 'B'.
✗ Incorrect
Use .loc to select the column labeled 'B' as a Series.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .iloc instead of .loc for label selection.
Using wrong column name when adding or selecting.
✗ Incorrect
Add the Series s2 as a new column 'Y' to the DataFrame, then select it using .loc.