Page 334 - Informatics_Practices_Fliipbook_Class12
P. 334

(viii)  Retrieve the number of occurrences for each unique product in the Product column.
              (ix)  Add a new column Total to the DataFrame to be calculated as Quantity * Price.

              (x)    Concatenate  the  DataFrame  purchaseDF  with  another  DataFrame  (purchaseDF2)  in  a  row-wise
                   manner.
              (xi)  Write the contents of the DataFrame purchaseDF to a CSV file named purchases.csv.

              (xii)  Group the DataFrame by Product and calculate the total values for each product.
              (xiii)  Drop the Date column from the DataFrame.
              (xiv)  Rename the column PurchaseID to ID.

         12.   Consider  the  DataFrame  purchaseDF  created  in  the  previous  question  and  determine  the  output  of  the
              following statements:

              (i)   purchaseDF.groupby('Product').count()
              (ii)  purchaseDF['Price'].mean()
              (iii)  purchaseDF['Quantity'].std()

              (iv)  purchaseDF['Price'].max()
              (v)  purchaseDF.iloc[3]['Product']
              (vi)  purchaseDF.loc[1:3, 'Date':'Quantity']

              (vii)  purchaseDF['Product'].value_counts()
              (viii)  purchaseDF['Product'].unique()
              (ix)  purchaseDF.groupby('Product')['Quantity'].mean()
              (x)   pd.concat([purchaseDF, purchaseDF], axis=1)

              (xi)  purchaseDF.rename(columns={'Quantity': 'Units'})
         13.   Consider  the  following  Pandas  DataFrame  plantDF  representing  data  related  to  different  types
              of plants:

              import pandas as pd
              data = {
                  'Plant Name': ['Rose', 'Tulip', 'Cactus', 'Fern', 'Daisy'],
                  'Height (cm)': [60, 25, 15, 30, 20],
                  'Bloom Season': ['Spring', 'Spring', 'Year-round', 'Summer', 'Spring'],

                  'Indoor/Outdoor': ['Outdoor', 'Outdoor', 'Indoor', 'Indoor', 'Outdoor'],
              }
              plantDF= pd.DataFrame(data)
              Determine the output on the execution of the following Python statements:
              (i)   print(plantDF.ndim)
              (ii)  print(plantDF.shape)

              (iii)  print(plantDF.index)
              (iv)  print(plantDF.columns)
              (v)  print(plantDF.head(3))

              (vi)  print(plantDF.tail(2))
              (vii)  print(plantDF.iloc[2])



          320  Touchpad Informatics Practices-XII
   329   330   331   332   333   334   335   336   337   338   339