Complete the code to create a DataFrame from a NumPy array named 'data'.
import pandas as pd import numpy as np data = np.array([[1, 2], [3, 4]]) df = pd.[1](data) print(df)
The pd.DataFrame() function creates a DataFrame from the NumPy array.
Complete the code to assign column names 'A' and 'B' when creating the DataFrame.
import pandas as pd import numpy as np data = np.array([[5, 6], [7, 8]]) df = pd.DataFrame(data, columns=[1]) print(df)
Column names must be passed as a list of strings to the columns parameter.
Fix the error in the code to correctly create a DataFrame from a NumPy array 'arr'.
import pandas as pd import numpy as np arr = np.array([[9, 10], [11, 12]]) df = pd.DataFrame(arr, columns=[1]) print(df)
The columns list must match the number of columns in the array. Here, the array has 2 columns, so provide 2 column names.
Fill both blanks to create a DataFrame from 'matrix' with index labels 'row1', 'row2'.
import pandas as pd import numpy as np matrix = np.array([[13, 14], [15, 16]]) df = pd.DataFrame(matrix, columns=[1], index=[2]) print(df)
Columns must match the number of columns in the array, and index must match the number of rows.
Fill all three blanks to create a DataFrame from 'arr' with columns 'X', 'Y' and index 'a', 'b'.
import pandas as pd import numpy as np arr = np.array([[17, 18], [19, 20]]) df = pd.DataFrame([1], columns=[2], index=[3]) print(df)
The first blank is the data array, the second is the column names list, and the third is the index list.