Complete the code to create a pandas Series from a list.
import pandas as pd my_list = [10, 20, 30] my_series = pd.[1](my_list) print(my_series)
We use pd.Series() to create a Series from a list.
Complete the code to create a DataFrame from two Series.
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)
To create a DataFrame with two columns, pass both Series as values in the dictionary.
Fix the error in the code to select a column from a DataFrame as a Series.
import pandas as pd df = pd.DataFrame({'X': [7, 8, 9], 'Y': [10, 11, 12]}) col = df[1]['X'] print(type(col))
Using .loc with the column label selects a Series. Using double brackets returns a DataFrame.
Fill both blanks to create a DataFrame from a dictionary of Series and select a Series column.
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)
Use .loc to select the column labeled 'B' as a Series.
Fill all three blanks to create a DataFrame, add a new Series column, and select it.
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)
Add the Series s2 as a new column 'Y' to the DataFrame, then select it using .loc.
