#import pandas
import pandas as pd
#Reading the csv file
df = pd.read_csv("JaipurFinalCleanData.csv")
type(df)
pandas.core.frame.DataFrame
# Exploring the data
df
date mean_temperature max_temperature min_temperature \
0 2016-05-04 34 41 27
1 2016-05-05 31 38 24
2 2016-05-06 28 34 21
3 2016-05-07 30 38 23
4 2016-05-08 34 41 26
.. ... ... ... ...
671 2018-03-07 24 32 15
672 2018-03-08 24 32 15
673 2018-03-09 26 33 19
674 2018-03-10 26 34 19
675 2018-03-11 26 34 18
Mean_dew_pt mean_pressure max_humidity min_humidity
max_dew_pt_1 \
0 6 1006.00 27 5
12
1 7 1005.65 29 6
13
2 11 1007.94 61 13
16
3 13 1008.39 69 18
17
4 10 1007.62 50 8
14
.. ... ... ... ...
...
671 4 1015.39 48 6
9
672 2 1014.07 55 5
8
673 1 1014.41 42 7
5
674 3 1014.16 37 8
6
675 4 1013.76 38 6
8
max_dew_pt_2 min_dew_pt_1 min_dew_pt_2 max_pressure_1
max_pressure_2 \
0 10 -2 -2 1009
1008
1 12 0 -2 1008
1009
2 13 6 0 1011
1008
3 16 9 6 1011
1011
4 17 6 9 1010
1011
.. ... ... ... ...
...
671 13 -3 0 1018
1017
672 9 -6 -3 1017
1018
673 8 -5 -6 1017
1017
674 5 -1 -5 1017
1017
675 6 0 -1 1017
1017
min_pressure_1 min_pressure_2 rainfall
0 1000 1001 0.0
1 1001 1000 0.0
2 1003 1001 5.0
3 1004 1003 0.0
4 1002 1004 0.0
.. ... ... ...
671 1012 1011 0.0
672 1011 1012 0.0
673 1011 1011 0.0
674 1009 1011 0.0
675 1009 1009 0.0
[676 rows x 17 columns]
#To access first 5 rows of data from the Jaipur csv file
print(df.head())
date mean_temperature max_temperature min_temperature \
0 2016-05-04 34 41 27
1 2016-05-05 31 38 24
2 2016-05-06 28 34 21
3 2016-05-07 30 38 23
4 2016-05-08 34 41 26
Mean_dew_pt mean_pressure max_humidity min_humidity
max_dew_pt_1 \
0 6 1006.00 27 5
12
1 7 1005.65 29 6
13
2 11 1007.94 61 13
16
3 13 1008.39 69 18
17
4 10 1007.62 50 8
14
max_dew_pt_2 min_dew_pt_1 min_dew_pt_2 max_pressure_1
max_pressure_2 \
0 10 -2 -2 1009
1008
1 12 0 -2 1008
1009
2 13 6 0 1011
1008
3 16 9 6 1011
1011
4 17 6 9 1010
1011
min_pressure_1 min_pressure_2 rainfall
0 1000 1001 0.0
1 1001 1000 0.0
2 1003 1001 5.0
3 1004 1003 0.0
4 1002 1004 0.0
#To access last 5 rows of data from the Jaipur csv file
df.tail()
date mean_temperature max_temperature min_temperature \
671 2018-03-07 24 32 15
672 2018-03-08 24 32 15
673 2018-03-09 26 33 19
674 2018-03-10 26 34 19
675 2018-03-11 26 34 18
Mean_dew_pt mean_pressure max_humidity min_humidity
max_dew_pt_1 \
671 4 1015.39 48 6
9
672 2 1014.07 55 5
8
673 1 1014.41 42 7
5
674 3 1014.16 37 8
6
675 4 1013.76 38 6
8
max_dew_pt_2 min_dew_pt_1 min_dew_pt_2 max_pressure_1
max_pressure_2 \
671 13 -3 0 1018
1017
672 9 -6 -3 1017
1018
673 8 -5 -6 1017
1017
674 5 -1 -5 1017
1017
675 6 0 -1 1017
1017
min_pressure_1 min_pressure_2 rainfall
671 1012 1011 0.0
672 1011 1012 0.0
673 1011 1011 0.0
674 1009 1011 0.0
675 1009 1009 0.0
# To find out the type of data (i.e., string, float, integer)
df.dtypes
date object
mean_temperature int64
max_temperature int64
min_temperature int64
Mean_dew_pt int64
mean_pressure float64
max_humidity int64
min_humidity int64
max_dew_pt_1 int64
max_dew_pt_2 int64
min_dew_pt_1 int64
min_dew_pt_2 int64
max_pressure_1 int64
max_pressure_2 int64
min_pressure_1 int64
min_pressure_2 int64
rainfall float64
dtype: object
# To Drop a column
df = df.drop(["max_dew_pt_2"], axis=1)
# To Drop a row at index 1
df = df.drop(1, axis=0)
# To Sort the values in descending order of date and print the first 5
rows
jaipur_weather = df.sort_values(by='date',ascending = False)
print(jaipur_weather.head())
date mean_temperature max_temperature min_temperature \
675 2018-03-11 26 34 18
674 2018-03-10 26 34 19
673 2018-03-09 26 33 19
672 2018-03-08 24 32 15
671 2018-03-07 24 32 15
Mean_dew_pt mean_pressure max_humidity min_humidity
max_dew_pt_1 \
675 4 1013.76 38 6
8
674 3 1014.16 37 8
6
673 1 1014.41 42 7
5
672 2 1014.07 55 5
8
671 4 1015.39 48 6
9
min_dew_pt_1 min_dew_pt_2 max_pressure_1 max_pressure_2 \
675 0 -1 1017 1017
674 -1 -5 1017 1017
673 -5 -6 1017 1017
672 -6 -3 1017 1018
671 -3 0 1018 1017
min_pressure_1 min_pressure_2 rainfall
675 1009 1009 0.0
674 1009 1011 0.0
673 1011 1011 0.0
672 1011 1012 0.0
671 1012 1011 0.0
# To Sort the values in ascending order of mean temperature and print
the first 5 rows
jaipur_weather = df.sort_values(by='mean_temperature',ascending =
True)
print(jaipur_weather.head())
date mean_temperature max_temperature min_temperature \
252 2017-01-11 10 18 3
253 2017-01-12 12 19 4
258 2017-01-17 12 20 5
255 2017-01-14 12 20 5
254 2017-01-13 12 20 4
Mean_dew_pt mean_pressure max_humidity min_humidity
max_dew_pt_1 \
252 3 1017.00 94 17
9
253 -3 1017.54 70 13
2
258 3 1017.35 74 15
7
255 -1 1017.75 70 10
1
254 -5 1017.24 75 4
2
min_dew_pt_1 min_dew_pt_2 max_pressure_1 max_pressure_2 \
252 -5 -1 1019 1018
253 -7 -5 1020 1019
258 -2 0 1019 1021
255 -8 -93 1020 1020
254 -93 -7 1020 1020
min_pressure_1 min_pressure_2 rainfall
252 1015 1014 0.0
253 1015 1015 0.0
258 1015 1015 0.0
255 1016 1015 0.0
254 1015 1015 0.0
# Using matplotlib to start plotting some graphs
import matplotlib.pyplot as plt
import numpy as np
# Scatter Plot
x = df.date
y = df.mean_temperature
plt.scatter(x,y)
plt.xticks(np.arange(0, 676, 60))
plt.xticks (rotation=90)
(array([ 0, 60, 120, 180, 240, 300, 360, 420, 480, 540, 600, 660]),
[Text(0, 0, ''),
Text(0, 0, ''),
Text(0, 0, ''),
Text(0, 0, ''),
Text(0, 0, ''),
Text(0, 0, ''),
Text(0, 0, ''),
Text(0, 0, ''),
Text(0, 0, ''),
Text(0, 0, ''),
Text(0, 0, ''),
Text(0, 0, '')])
# Add x and y labels and set a font size
plt.xlabel ("Date", fontsize = 14)
plt.ylabel ("Mean Temperature", fontsize = 14)
plt.title('Mean Temperature at Jaipur', fontsize = 20)
plt.show()
# Line Plots
plt.figure(figsize=(20,10))
x = df.date
y_1 = df.max_temperature
y_2 = df.min_temperature
y_3 = df.mean_temperature
z = y_1-y_2
plt.plot(x,y_1, label = "Max temp")
plt.plot(x,y_2, label = "Min temp")
plt.plot(x,y_3, label = "Mean temp")
plt.plot(x,z, label = "range")
plt.xticks(np.arange(0, 676, 60))
plt.xticks (rotation=30)
plt.legend()
plt.show()