Page 335 - Informatics_Practices_Fliipbook_Class12
P. 335
(viii) print(plantDF.loc[4, 'Plant Name'])
(ix) print(plantDF.set_index('Plant Name'))
(x) print(plantDF[plantDF['Height (cm)'] > 20])
(xi) print(plantDF[plantDF['Bloom Season'] == 'Spring'])
14. Consider the DataFrame plantDF mentioned in the previous question and write the code snippet for the
following queries:
(i) Retrieve the columns Plant Name and Height (cm).
(ii) Retrieve rows with Height (cm) greater than 20.
(iii) Retrieve rows where Bloom Season is Spring.
(iv) Use the iloc function to select the rows from index 2 to index 4.
(v) Set row labels to ['A', 'B', 'C', 'D', 'E']. What is the updated DataFrame?
(vi) Retrieve the summary statistics of the DataFrame.
(vii) Determine the minimum plant height.
(viii) Retrieve the number of occurrences for each unique value in the Indoor/Outdoor column.
(ix) Add a new column 'Volume' to the DataFrame to be calculated as (Height (cm))^2 * π.
(x) Concatenate the DataFrame plantDF with the following DataFrame plantDF2 in a row-wise manner.
(xi) Write the contents of the DataFrame plantDF to a CSV file named plants.csv.
(xii) Group the DataFrame by Indoor/Outdoor and calculate the average values for each group.
(xiii) Drop the Bloom Season column from the DataFrame.
(xiv) Rename the column Height (cm) to Plant Height.
15. Consider the DataFrame plantDF created in the previous question and determine the output of the following
statements:
(i) plantDF.groupby('Indoor/Outdoor').count()
(ii) plantDF['Height (cm)'].mean()
(iii) plantDF['Height (cm)'].std()
(iv) plantDF['Height (cm)'].max()
(v) plantDF.iloc[2]['Plant Name']
(vi) plantDF.loc['A':'C', 'Plant Name':'Bloom Season']
(vii) plantDF['Indoor/Outdoor'].value_counts()
(viii) plantDF['Bloom Season'].unique()
(ix) plantDF.groupby('Bloom Season')['Height (cm)'].mean()
(x) pd.concat([plantDF, plantDF], axis=1)
(xi) plantDF.rename(columns={'Plant Name': 'Full Name', 'Height (cm)': 'Plant Height'})
16. Consider a dataset representing the number of books borrowed from a library on a daily basis for a week: [30,
45, 60, 55, 70, 80, 65]. Write a Python program using Matplotlib to create a line plot to visualize
the daily borrowing trends. Add appropriate labels for the axes and title for the Figure. Also, the Figure should
include gridlines and be saved as "bookBorrowingTrend.png."
Practical 321

