Complete the code to create a DataFrame with columns named 'A' and 'B'.
import pandas as pd data = [[1, 2], [3, 4]] df = pd.DataFrame(data, columns=[1]) print(df)
The columns parameter sets the column names. Here, ['A', 'B'] names the columns correctly.
Complete the code to set the index of the DataFrame to the 'Name' column.
import pandas as pd data = {'Name': ['Alice', 'Bob'], 'Age': [25, 30]} df = pd.DataFrame(data) df = df.set_index([1]) print(df)
The set_index method sets the DataFrame index. Using 'Name' sets the index to the 'Name' column.
Fix the error in the code to correctly specify column names when creating the DataFrame.
import pandas as pd data = [[5, 6], [7, 8]] df = pd.DataFrame(data, columns=[1]) print(df)
The columns parameter requires a list of strings. ['A', 'B'] is the correct format.
Fill both blanks to create a DataFrame with columns 'X' and 'Y' and set 'X' as the index.
import pandas as pd data = [[9, 10], [11, 12]] df = pd.DataFrame(data, columns=[1]) df = df.set_index([2]) print(df)
First, specify the columns as ['X', 'Y']. Then set the index to the column 'X'.
Fill all three blanks to create a DataFrame with columns 'Name' and 'Score', set 'Name' as index, and print the DataFrame.
import pandas as pd data = [['John', 88], ['Jane', 92]] df = pd.DataFrame(data, columns=[1]) df = df.set_index([2]) print([3])
Specify columns as ['Name', 'Score'], set index to 'Name', and print the DataFrame df.