Page 338 - Informatics_Practices_Fliipbook_Class12
P. 338

(x)    Concatenate  the  DataFrame  'weatherDF'  with  a  similar  DataFrame  weatherDF2  in  a  row-wise
                   manner.
              (xi)  Write the contents of the DataFrame weatherDF to a CSV file named weather_data.csv.
              (xii)  Group the DataFrame by Temperature and calculate the average Humidity for each group.
              (xiii)  Drop the Wind_Speed column from the DataFrame.
              (xiv)  Rename the Humidity column to 'Relative Humidity'.
         30.  Consider the DataFrame weatherDF created in the Practice Task 9 and determine the output of the following
              statements:
              (i)   weatherDF.groupby('Humidity').count()

              (ii)  weatherDF['Wind_Speed'].mean()
              (iii)  weatherDF['Temperature'].std()
              (iv)  weatherDF['Humidity'].max()
              (v)  weatherDF.iloc[3]['Date']

              (vi)  weatherDF.loc[1:3, 'Date':'Temperature']
              (vii)  weatherDF['Temperature'].value_counts()
              (viii)  weatherDF['Temperature'].unique()
              (ix)  weatherDF.groupby('Wind_Speed')['Humidity'].mean()
              (x)   pd.concat([weatherDF, weatherDF], axis=1)

              (xi)  weatherDF.rename(columns={'Date': 'Day', 'Temperature': 'Temp'})
         31.  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)
              Determine the output of the following Python statements:
              (i)   print(transportDF.ndim)
              (ii)  print(transportDF.shape)
              (iii)  print(transportDF.index)
              (iv)  print(transportDF.columns)

              (v)  print(transportDF.head(3))
              (vi)  print(transportDF.tail(2))
              (vii)  print(transportDF.iloc[1])
              (viii)  print(transportDF.loc[3, 'Mode'])
              (ix)  print(transportDF.set_index('Mode'))

              (x)   print(transportDF[transportDF['Speed (km/h)'] > 50])
              (xi)  print(transportDF[transportDF['Capacity'] < 10])


          324  Touchpad Informatics Practices-XII
   333   334   335   336   337   338   339   340   341   342   343