Complete the code to create a pandas Series from a list.
import pandas as pd numbers = [10, 20, 30, 40] series = pd.Series([1]) print(series)
The pd.Series() function takes a list as input to create a Series. Here, we pass the variable numbers which holds the list.
Complete the code to create a pandas Series from a dictionary.
import pandas as pd scores = {'Alice': 85, 'Bob': 90, 'Cara': 78} series = pd.Series([1]) print(series)
The pd.Series() function can take a dictionary to create a Series where keys become the index and values become the data.
Fix the error in the code to create a Series from a list with custom index labels.
import pandas as pd values = [100, 200, 300] labels = ['a', 'b', 'c'] series = pd.Series(values, index=[1]) print(series)
The index parameter expects a list or array of labels. Here, labels is the variable holding the list of index labels.
Fill both blanks to create a Series from a dictionary and set a custom name for the Series.
import pandas as pd data = {'x': 1, 'y': 2, 'z': 3} series = pd.Series([1], name=[2]) print(series)
The first blank is the dictionary variable data to create the Series. The second blank is the name of the Series as a string.
Fill all three blanks to create a Series from a list, set custom index labels, and assign a name.
import pandas as pd values = [5, 10, 15] labels = ['p', 'q', 'r'] series = pd.Series([1], index=[2], name=[3]) print(series)
The first blank is the list of values, the second blank is the list of index labels, and the third blank is the name of the Series as a string.