Page 321 - Informatics_Practices_Fliipbook_Class12
P. 321

(iii)  Retrieve and display the data for the fourth day (2023-01-04) using iloc.
                 (iv)  Retrieve and display the temperature and humidity data for the first three days using loc.
                 (v)  Retrieve and display the wind speed data for the last two days using iloc.

            Ans. (i)   weatherDF = pd.DataFrame(weatherData)

                     print(weatherDF)
                 (ii)  data = weatherDF.loc[1]


                     print('Data for the second day (2023-01-02):')
                     print(data)
                 (iii)  data = weatherDF.iloc[3]

                     print('Data for the fourth day (2023-01-04):')

                     print(data)
                 (iv)  data = weatherDF.loc[0:2, ['Date', 'Temperature', 'Humidity']]

                     print('Temperature and humidity data for the first three days:')

                     print(data)
                 (v)  data = weatherDF.iloc[3:5, 3]

                     print('Wind speed data for the last two days:')

                     print(data)

            Program 10: Consider the following Pandas DataFrame transportDF representing data related to different modes of
            transport:

                 import pandas as pd
                 data = {

                     'Mode': ['Car', 'Bus', 'Train', 'Bicycle', 'Walking'],
                     'Speed (km/h)': [100, 60, 120, 20, 5],

                     'Capacity': [4, 60, 500, 1, 1],
                     'Fuel Efficiency (km/l)': [12, 4, 0, 0, 0],

                 }
                 transportDF = pd.DataFrame(data)
                 Write the code snippet for the following queries:

                 (i)   Retrieve the columns Mode and Capacity.
                 (ii)  Retrieve rows with Speed (km/h) greater than 50.
                 (iii)  Retrieve rows where Fuel Efficiency (km/l) is zero.

                 (iv)  Use the iloc function to select the rows from index 1 to index 3.
                 (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 maximum speed (Speed (km/h)) among all modes of transport.


                                                                                                      Practical  307
   316   317   318   319   320   321   322   323   324   325   326