Page 437 - AI Ver 3.0 Class 11
P. 437
'Ingredients': [
'Tomato, Mozzarella, Basil',
'Tomato, Mozzarella, Pepperoni',
'BBQ Sauce, Chicken, Mozzarella',
'Tomato, Mozzarella, Bell Peppers, Onions, Olives',
'Tomato, Mozzarella, Ham, Pineapple'],
'Vegetarian': [True, False, False, True, False]
}
df = pd.DataFrame(data)
# Display the first few rows of the DataFrame
print(df.head())
Output:
Pizza Name Size Price \
0 Margherita Small 8.99
1 Pepperoni Medium 10.99
2 BBQ Chicken Large 12.99
3 Veggie Medium 9.99
4 Hawaiian Small 11.49
Ingredients Vegetarian
0 Tomato, Mozzarella, Basil True
1 Tomato, Mozzarella, Pepperoni False
2 BBQ Sauce, Chicken, Mozzarella False
3 Tomato, Mozzarella, Bell Peppers, Onions, Olives True
4 Tomato, Mozzarella, Ham, Pineapple False
16. Create a DataFrame df with some missing values: {‘A’: [1, 2, np.nan, 4], ‘B’: [5, np.nan, np.nan, 8], ‘C’: [9, 10, 11, 12]}.
Fill the missing values in column ‘A’ with the mean of the column.
import pandas as pd
import numpy as np
data = {'A': [1, 2, np.nan, 4], 'B': [5, np.nan, np.nan, 8], 'C': [9, 10, 11, 12]}
df = pd.DataFrame(data)
df['A'].fillna(df['A'].mean(), inplace=True)
print(df)
Output:
A B C
0 1.000000 5.0 9
1 2.000000 NaN 10
2 2.333333 NaN 11
3 4.000000 8.0 12
17. Write a program to create series from an array in Python. [CBSE HANDBOOK]
import numpy as np
import pandas as pd
# Create a NumPy array
array = np.array([23, 25, 30, 35, 50])
# Create a Pandas Series from the NumPy array
series = pd.Series(array)
# Print the Series
print(series)
Practical Questions 435

