Robotics & Artificial Intelligence
What would be the output of the following code?
import pandas as pd
# Create a DataFrame
data = {'Name':['Jai', 'Ella', 'Mike', 'Pihu'],
'Age':[25, 28, 30, 22],
'City':['New York', 'London', 'Paris', 'Sydney']}
df = pd.DataFrame(data)
print(df['Age'] > 29)
Answer
Output
0 False
1 False
2 True
3 False
Name: Age, dtype: bool
Explanation
1. import pandas as pd — The pandas library is imported and renamed as pd.
2. A dictionary named data is created. It contains three keys: Name, Age, and City. Each key has a list of values.
3. df = pd.DataFrame(data) — The DataFrame() function of the Pandas library is used to convert the dictionary into a DataFrame.
4. print(df['Age'] > 29) — The Age column is selected from the DataFrame. Each value in the Age column is compared with 29. The condition returns True if the age is greater than 29, otherwise False.