Q. Given the data-set for weather forecast:


day: ['01/01/2018', '01/02/2018', '01/03/2018', '01/04/2018', '01/05/2018', '01/01/2018']
temperature: [42, 41, 43, 42, 41, 40]
windspeed: [6, 7, 2, 4, 7, 2]
event: ['Sunny', 'Rain', 'Sunny', 'Sunny', 'Rain', 'Sunny']

Perform all the aggregate and statistical functions you have learnt in the chapter on the basis of the given dataset.


Note: Create dataframe for the given dataset before applying the functions.

Answer :-

import pandas as pd
 
weather_data = {'day': ['01/01/2018','01/02/2018', '01/03/2018','01/04/2018','01/05/2018', '01/01/2018'],
  'temperature': [42, 41, 43, 42, 41, 40],
  'windspeed': [6,7,2,4,7,2],
  'event':['Sunny', 'Rain', 'Sunny', 'Sunny', 'Rain', 'Sunny']}
 
df = pd.DataFrame(weather_data)
 
print (df)
print ("Number of Rows and Columns")
print (df.shape)
print (df.head ())
print ("Tail")
print (df.tail (2))
print("Specified Number of Rows")
print (df [2:5])
print ("Print Everything")
print (df[:])
print ("Print Column Names")
print (df.columns)
print ("Data from Individual Column")
print (df['day'])
print (df['temperature'])
print ("Maximum Temperature: ", df['temperature'].max ())


Output :-

  day temperature windspeed event
0 01/01/2018 42 6 Sunny
1 01/02/2018 41 7 Rain
2 01/03/2018 43 2 Sunny
3 01/04/2018 42 4 Sunny
4 01/05/2018 41 7 Rain
5 01/01/2018 40 2 Sunny
Number of Rows and Columns
(6, 4)
  day temperature windspeed event
0 01/01/2018 42 6 Sunny
1 01/02/2018 41 7 Rain
2 01/03/2018 43 2 Sunny
3 01/04/2018 42 4 Sunny
4 01/05/2018 41 7 Rain
Tail
  day temperature windspeed event
4 01/05/2018 41 7 Rain
5 01/01/2018 40 2 Sunny
Specified Number of Rows
  day temperature windspeed event
2 01/03/2018 43 2 Sunny
3 01/04/2018 42 4 Sunny
4 01/05/2018 41 7 Rain
Print Everything
  day temperature windspeed event
0 01/01/2018 42 6 Sunny
1 01/02/2018 41 7 Rain
2 01/03/2018 43 2 Sunny
3 01/04/2018 42 4 Sunny
4 01/05/2018 41 7 Rain
5 01/01/2018 40 2 Sunny
Print Column Names
Index(['day', 'temperature', 'windspeed', 'event'], dtype='object')
Data from Individual Column
0 01/01/2018
1 01/02/2018
2 01/03/2018
3 01/04/2018
4 01/05/2018
5 01/01/2018
Name: day, dtype: object
0 42
1 41
2 43
3 42
4 41
5 40
Name: temperature, dtype: int64
Maximum Temperature: 43

>>>

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post