KEMBAR78
Data Science | PDF
0% found this document useful (0 votes)
8 views18 pages

Data Science

The document contains Python code that processes a weather dataset using pandas, including reading a CSV file, cleaning the data by dropping certain columns, and sorting it by date. It also includes various visualizations of temperature data using matplotlib, such as scatter plots, bar charts, and line graphs. The code demonstrates how to manipulate and visualize weather data effectively.

Uploaded by

S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views18 pages

Data Science

The document contains Python code that processes a weather dataset using pandas, including reading a CSV file, cleaning the data by dropping certain columns, and sorting it by date. It also includes various visualizations of temperature data using matplotlib, such as scatter plots, bar charts, and line graphs. The code demonstrates how to manipulate and visualize weather data effectively.

Uploaded by

S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

import pandas as pd

dataframe=pd.read_csv("/content/mydata.csv")

date1 mean_temperature max_temperature min_temperature \


0 04-05-2016 34 41 27
1 05-05-2016 31 38 24
2 06-05-2016 28 34 21
3 07-05-2016 30 38 23
4 08-05-2016 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

print (dataframe.head(10))

date1 mean_temperature max_temperature min_temperature \


0 04-05-2016 34 41 27
1 05-05-2016 31 38 24
2 06-05-2016 28 34 21
3 07-05-2016 30 38 23
4 08-05-2016 34 41 26
5 09-05-2016 34 42 27
6 10-05-2016 34 41 27
7 11-05-2016 32 40 25
8 12-05-2016 34 42 27
9 13-05-2016 34 42 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
5 8 1006.73 32 7
12
6 11 1005.75 45 7
16
7 16 1007.10 51 12
18
8 16 1006.78 66 16
22
9 13 1003.83 58 9
20

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
5 14 6 6 1010
1010
6 12 7 6 1008
1010
7 16 13 7 1010
1008
8 18 10 13 1011
1010
9 22 10 10 1007
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
5 1002 1002 0.0
6 1000 1002 0.3
7 1002 1000 0.8
8 1001 1002 2.0
9 998 1001 0.3

dataframe.dtypes

date1 object
mean_temperature int64
max_temperature int64
min_temperature int64
mean_pressure float64
max_humidity int64
max_dew_pt_1 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

dataframe = dataframe.drop(["min_dew_pt_2"], axis=1)

dataframe.dtypes

date1 object
mean_temperature int64
max_temperature int64
min_temperature int64
mean_pressure float64
max_humidity int64
max_dew_pt_1 int64
min_dew_pt_1 int64
max_pressure_1 int64
max_pressure_2 int64
min_pressure_1 int64
min_pressure_2 int64
rainfall float64
dtype: object

dataframe = dataframe.drop(["min_dew_pt_1", "max_pressure_2",


"min_pressure_2"], axis=1)

dataframe.dtypes

date1 object
mean_temperature int64
max_temperature int64
min_temperature int64
mean_pressure float64
max_humidity int64
max_dew_pt_1 int64
max_pressure_1 int64
min_pressure_1 int64
rainfall float64
dtype: object

dataframe_weather=dataframe.sort_values(by='date1', ascending=False)
print(dataframe_weather.head(25))

date1 mean_temperature max_temperature min_temperature \


13 17-05-2016 35 44 26
12 16-05-2016 36 43 28
11 15-05-2016 36 44 29
10 14-05-2016 35 42 28
9 13-05-2016 34 42 26
8 12-05-2016 34 42 27
7 11-05-2016 32 40 25
6 10-05-2016 34 41 27
5 09-05-2016 34 42 27
4 08-05-2016 34 41 26
3 07-05-2016 30 38 23
2 06-05-2016 28 34 21
1 05-05-2016 31 38 24
0 04-05-2016 34 41 27

Mean_dew_pt mean_pressure max_humidity min_humidity


max_dew_pt_1 \
13 13 1003.68 51 6
19
12 12 1005.02 40 7
16
11 13 1004.74 48 8
19
10 11 1003.56 40 9
16
9 13 1003.83 58 9
20
8 16 1006.78 66 16
22
7 16 1007.10 51 12
18
6 11 1005.75 45 7
16
5 8 1006.73 32 7
12
4 10 1007.62 50 8
14
3 13 1008.39 69 18
17
2 11 1007.94 61 13
16
1 7 1005.65 29 6
13
0 6 1006.00 27 5
12

max_dew_pt_2 min_dew_pt_1 min_dew_pt_2 max_pressure_1


max_pressure_2 \
13 16 7 9 1006
1008
12 19 9 10 1008
1007
11 16 10 7 1007
1006
10 20 7 10 1006
1007
9 22 10 10 1007
1011
8 18 10 13 1011
1010
7 16 13 7 1010
1008
6 12 7 6 1008
1010
5 14 6 6 1010
1010
4 17 6 9 1010
1011
3 16 9 6 1011
1011
2 13 6 0 1011
1008
1 12 0 -2 1008
1009
0 10 -2 -2 1009
1008

min_pressure_1 min_pressure_2 rainfall


13 999 1001 3.0
12 1001 1000 0.0
11 1000 998 0.0
10 998 998 0.0
9 998 1001 0.3
8 1001 1002 2.0
7 1002 1000 0.8
6 1000 1002 0.3
5 1002 1002 0.0
4 1002 1004 0.0
3 1004 1003 0.0
2 1003 1001 5.0
1 1001 1000 0.0
0 1000 1001 0.0

import matplotlib.pyplot as plt


import numpy as np
x=dataframe.date1
y=dataframe.mean_temperature
plt.scatter(x,y)
plt.show

<function matplotlib.pyplot.show(close=None, block=None)>


plt.scatter(x,y)
plt.xticks(np.arange(0,13,2))
plt.xticks(rotation=30)
plt.xlabel("Date7", fontsize=14)
plt.ylabel("Mean_Temp", fontsize=14)
plt.title('Mean Temp at Jaipur')
plt.show

<function matplotlib.pyplot.show(close=None, block=None)>


plt.bar(x,y)
plt.xticks(np.arange(0,13,2))
plt.xticks(rotation=30)
plt.xlabel("Date7", fontsize=14)
plt.ylabel("Mean_Temp", fontsize=14)
plt.title('Mean Temp at Jaipur')
plt.show

<function matplotlib.pyplot.show(close=None, block=None)>


plt.plot(x,y)
plt.xticks(np.arange(0,13,2))
plt.xticks(rotation=30)
plt.xlabel("Date7", fontsize=14)
plt.ylabel("Mean_Temp", fontsize=14)
plt.title('Mean Temp at Jaipur')
plt.show

<function matplotlib.pyplot.show(close=None, block=None)>


plt.figure(figsize=(5,5))
plt.scatter(x,y)
plt.xticks(np.arange(0,13,2))
plt.xticks(rotation=30)
plt.scatter(x,y,c='red', marker='*')
plt.xlabel("Date7", fontsize=14)
plt.ylabel("Mean_Temp", fontsize=14)
plt.title('Mean Temp at Jaipur')
plt.xticks (fontsize = 12)
plt.yticks (fontsize = 12)
plt.show

<function matplotlib.pyplot.show(close=None, block=None)>


plt.scatter(x,y)
plt.xticks(np.arange(0,13,2))
plt.xticks(rotation=30)
plt.scatter(x,y, marker='+')
plt.scatter(x,y, c='blue', marker='+')
plt.xticks(np.arange(0, 15, 1))
plt.xticks (rotation=30)
plt.xlabel("Date7", fontsize=14)
plt.ylabel("Mean_Temp", fontsize=14)
plt.title('Mean Temp at Jaipur')
plt.xticks (fontsize = 5)
plt.yticks (fontsize = 5)
plt.savefig("graph1.png")
plt.show

<function matplotlib.pyplot.show(close=None, block=None)>


plt.figure(figsize=(5,5))
plt.plot(x,y, "o:r")
plt.ylabel("Mean Temperature")
plt.xlabel("Time")
plt.xticks(np.arange(0,13,2) , rotation=30)
plt.xticks()
y = dataframe.mean_temperature
plt.show()
import matplotlib.pyplot as plt
import numpy as np
plt.figure(figsize=(5,5))
dataframe1=pd.read_csv("/content/mydata.csv")
dataframe1.dtypes
x=dataframe1.mean_temperature
plt.hist(x, color="purple")
plt.show()
x = dataframe.date1
y_1 = dataframe.max_temperature
y_2 = dataframe.min_temperature
plt.figure(figsize=(5,5))
plt.plot(x,y_1, label = "Max temp")
plt.plot(x,y_2, label = "Min temp")
plt.xticks(np.arange(0,13,2))
plt.xticks (rotation=30)
plt.legend()
plt.show()
x = dataframe.date1
y_1 = dataframe.max_temperature
y_2 = dataframe.min_temperature
y_3 = dataframe.mean_temperature
z = y_1-y_2
plt.figure(figsize=(5,5))
plt.bar(x,y_1, label = "Max temp")
plt.bar(x,y_2, label = "Min temp")
plt.bar(x,y_3, label = "Mean temp")
plt.bar(x,z, label = "range")
plt.xticks(np.arange(0, 15, 1))
plt.xticks (rotation=30)
plt.legend()
plt.show()
x = dataframe.date1
y_1 = dataframe.max_temperature
y_2 = dataframe.min_temperature
y_3 = dataframe.mean_temperature
z = y_1-y_2
plt.figure(figsize=(10,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, 15, 1))
plt.xticks (rotation=30)
plt.legend()
plt.show()
import matplotlib.pyplot as plt
import numpy as np
dataframe=pd.read_csv("/content/mydata.csv")
x=dataframe.date1
y_1=dataframe.max_temperature
plt.figure(figsize=(5,5))
plt.pie(y_1, labels=x)
plt.show

<function matplotlib.pyplot.show(close=None, block=None)>

dataframe=pd.read_csv("/content/mydata.csv")
x=dataframe.date1
y_1=dataframe.max_temperature
mycolors = ["black", "purple", "b", "#1CAF10"]
plt.figure(figsize=(5,5))
plt.pie(y_1, labels=x)
plt.pie(y_1, labels = x)
plt.pie(y_1, labels = x, colors = mycolors)
#plt.legend()
plt.show()

You might also like