# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/shrutibalan4591/github-slideshow/blob/main/weather.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + [markdown] id="dFEl5uznVB8B"
# # Importing libraries and reading file

# + id="CUwx43FAVHLB"
# Import necessary libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# %matplotlib inline
import warnings
warnings.filterwarnings("ignore")
import datetime as dt
import calendar




# + id="Acd6cGkLqk2u" colab={"base_uri": "https://localhost:8080/", "height": 306} outputId="e9b3d437-e6dc-4899-b70a-8d5ec8e9399a"
# Load datasets
data_w = pd.read_csv('/content/drive/MyDrive/Weather History/weatherHistory.csv')
data_w.head()

# + [markdown] id="DfuihKuWWBe3"
# # Data Cleaning

# + colab={"base_uri": "https://localhost:8080/"} id="I5PjLRHcWENC" outputId="3270575f-6c71-47e1-ae5c-fa2ddde97a2c"
# No. of rows and columns
data_w.shape

# + [markdown] id="shx1hXg67Msu"
# Look for any duplicates

# + colab={"base_uri": "https://localhost:8080/"} id="kSQJ1XccWYum" outputId="fe28f18d-d916-4216-bdc8-653ccfe97983"
# Check for duplicate rows
data_w.drop_duplicates()
data_w.shape

# + [markdown] id="NXA-ULK37P9q"
# No duplicates were found. Next check for validity of datatypes

# + colab={"base_uri": "https://localhost:8080/"} id="NYGam6qcWGN6" outputId="2b8e85e3-92ea-4773-e438-5516fc568398"
# Check datatypes
data_w.dtypes

# + [markdown] id="8NDT4_-j7Ypt"
# Formatted Date is assigned values of type object. Change it to datetime datatype.

# + id="vo_xoPqWb6fk" colab={"base_uri": "https://localhost:8080/", "height": 306} outputId="765a9f17-b572-4296-e499-cc4a8e984077"
# Change data type of Formatted date
data_w['Formatted Date'] = pd.to_datetime(data_w['Formatted Date'], utc=True)
data_w.head()

# + [markdown] id="PsdRhshL7nwq"
# Check for null values

# + colab={"base_uri": "https://localhost:8080/"} id="dFEQOaRza4Md" outputId="2bb76ed5-02e6-47b1-8f34-67e61a6619a6"
# Check for null values
data_w.isnull().sum()

# + [markdown] id="XenUl7m4Acy0"
# # Data Analysis

# + id="I46FyfS0bqAC" colab={"base_uri": "https://localhost:8080/", "height": 235} outputId="dff8cf91-3449-444d-b6f4-043ff6ba71bc"
# Create a new dataframe from data_w with necessary columns
data_n = data_w[['Formatted Date', 'Apparent Temperature (C)', 'Humidity']]
data_n.set_index('Formatted Date', inplace=True)
data_n.head()

# + [markdown] id="WTXUgaPX7qjM"
# Analysing with hourly data on a high level is difficult. So we resample the data to month level

# + colab={"base_uri": "https://localhost:8080/", "height": 235} id="xlt6IS85wZFw" outputId="195e756a-f766-42fc-dafc-0b2e2ddf7b96"
# Resample data monthwise
data_n = data_n[['Apparent Temperature (C)', 'Humidity']].resample('MS').mean()
data_n.head()

# + [markdown] id="4g_2_haD777B"
# ### Plotting

# + colab={"base_uri": "https://localhost:8080/", "height": 355} id="6dkOM3_2qh6t" outputId="c92292a3-552b-4d87-d81e-3f6678d72439"
# Plotting apparent temperature and humidity from 2006 to 2016
plt.figure(figsize=(20,5))
plt.title('Apparent temperature v/s humidity from 2006 to 2016')
sns.lineplot(data=data_n)
plt.xlabel('Dates')
plt.legend(loc = 0, fontsize = 12)
plt.xticks(fontsize = 15)
plt.yticks(fontsize = 13)
plt.show()

# + id="ZQPLVi8cAUAt" colab={"base_uri": "https://localhost:8080/", "height": 355} outputId="c0f6ba8e-4cd5-43fb-d001-db7e7e0e39b4"
# Lets plot the graph for April month
april = data_n[data_n.index.month==4]
plt.figure(figsize=(20,5))
plt.title('Apparent temperature v/s humidity from 2006 to 2016 for the month of April')
sns.lineplot(data=april, markers=['o', 'o'])
plt.xlabel('Dates')
plt.legend(loc = 0, fontsize = 12)
plt.xticks(fontsize = 15)
plt.yticks(fontsize = 13)
plt.show()

# + colab={"base_uri": "https://localhost:8080/", "height": 1000} id="O8KzPI1UHWeB" outputId="71980ca1-7f62-4df6-952a-5d93d12ddcd9"
# Lets plot the graph for each month separately
for i in range(12):
  i = i+1
  mon = data_n[data_n.index.month==i]
  plt.figure(figsize=(20,5))
  plt.title('Apparent temperature v/s humidity from 2006 to 2016 for the month of ' + calendar.month_name[i])
  sns.lineplot(data=mon, markers=['o', 'o'])
  plt.xlabel('Dates')
  plt.legend(loc = 0, fontsize = 12)
  plt.xticks(fontsize = 15)
  plt.yticks(fontsize = 13)
  plt.show()

# + id="VXmg8k7bOcIX"


StarcoderdataJupyterScriptsDedupFiltered