CBSE Class 12 Informatics Practices
Question 75 of 167
Python Pandas — I — Question 40
Back to all questions 40
Question Sudhanshu has written the following code to create a DataFrame with boolean index :
import numpy as np
import pandas as pd
df = pd.DataFrame(data = [[5, 6, 7]], index = [true, false, true])
print(df)While executing the code, she is getting an error, help her to rectify the code :
- df = pd.DataFrame([True, False, True], data = [5, 6, 7])
- df = pd.DataFrame(data = [5, 6, 7], index = [True, False, True])
- df = pd.DataFrame([true, false, true], data = [5, 6, 7])
- df = pd.DataFrame(index = [true, false, true], data = [[5, 6, 7]])
df = pd.DataFrame(data = [5, 6, 7], index = [True, False, True])
Reason — The index values 'true' and 'false' should have the first letter capitalized to match Python's boolean values. Also, the 'data' parameter should contain the list of values to be included in the DataFrame. Hence, df = pd.DataFrame(data = [5, 6, 7], index = [True, False, True]) is correct.