diff --git a/12_09_practice.py b/12_09_practice.py index 7914563..2e5b05f 100644 --- a/12_09_practice.py +++ b/12_09_practice.py @@ -1,29 +1,204 @@ #Biggie Size - Given a list, write a function that changes all positive numbers in the list to "big". Example: make_it_big([-1, 3, 5, -5]) returns that same list, #changed to [-1, "big", "big", -5]. +# Function that changes all positive numbers to the string "big" +def make_it_big(output_list): + + for position, number in enumerate(output_list): + # Checking if the number is positive + if number > 0: + # Assigning the value "big" to the positive number + output_list[position] = "big" + return output_list + +biggie_size = [-1, 3, 5, -5] +# Calling the function to change all positive numbers to the string "big" +make_it_big(biggie_size) +print(biggie_size) + #Count Positives - Given a list of numbers, create a function to replace last value with number of positive values. Example, count_positives([-1,1,1,1]) changes list #to [-1,1,1,3] and returns it. (Note that zero is not considered to be a positive number). +# Function to replace last value with the count of positive values +def count_positives(output_list): + total = 0 + for number in output_list: + # Checking if the number is positive + if number > 0: + # Adding the positive numbers + total += number + # Assigning the sum of all positive values to the last value of the list + output_list[-1] = total + return output_list + +input_list = [-1, 1, 1, 1] +# Calling the function to count the positive numbers +count_positives(input_list) +print(input_list) + #SumTotal - Create a function that takes a list as an argument and returns the sum of all the values in the list. For example sum_total([1,2,3,4]) should return 10 +# Function to return the sum of all values +def sumtotal(output_list): + return sum(output_list) + +input_list = [1, 2, 3, 4] +print(sumtotal(input_list)) + #Average - Create a function that takes a list as an argument and returns the average of all the values in the list. For example multiples([1,2,3,4]) should return #2.5 +# Function to return the average of all the values in the list +def average(output_list): + # Returns the average of the values in the list + return sum(output_list)/len(output_list) + +input_list = [1, 2, 3, 4] +avg = 0 +avg = average(input_list) +print(avg) + #Length - Create a function that takes a list as an argument and returns the length of the list. For example length([1,2,3,4]) should return 4 +# Function to get the length of the list +def length(output_list): + # Returning the length og the list + return len(output_list) + +input_list = [1, 2, 3, 4] +lgth = 0 +# Calling the function to find the length of the list +lgth = length(input_list) +print(lgth) + #Minimum - Create a function that takes a list as an argument and returns the minimum value in the list. If the passed list is empty, have the function return false. #For example minimum([1,2,3,4]) should return 1; minimum([-1,-2,-3]) should return -3. -# + +# Function to get the minimum value from the list +def minimum(output_list): + # Cheking if the list is empty and if so returning false + if len(output_list) == 0: + return False + else: + return min(output_list) + +input_list = [1, 2, 3, 4] +#input_list = [-1, -2, -3] +#input_list = [] +minmum = 0 +# Calling the function minimum to get the minimum value from the list +minmum = minimum(input_list) +print(minmum) + + #Maximum - Create a function that takes a list as an argument and returns the maximum value in the list. If the passed list is empty, have the function return false. #For example maximum([1,2,3,4]) should return 4; maximum([-1,-2,-3]) should return -1. +# Function to get the maximum value from the list +def maximum(output_list): + # Checking if the list is empty and if so returning false + if len(output_list) == 0: + return False + else: + return max(output_list) + +input_list = [1, 2, 3, 4] +#input_list = [-1, -2, -3] +#input_list = [] +maxmum = 0 +# Calling the function to get the maximum value from the list +maxmum = maximum(input_list) +print(maxmum) + + #Ultimateaalyze - Create a function that takes a list as an argument and returns a dictionary that has the sumTotal, average, minimum, maximum ad length of the list. +# Function to get the sumtotal, average, minimum, maximum and length of the list +def ultimateanalyze(output_list): + output_dictionary = {} + # Adding entries to the dictionary + output_dictionary['sumtotal'] = sum(output_list) + output_dictionary['average'] = sum(output_list)/len(output_list) + output_dictionary['minimum'] = min(output_list) + output_dictionary['maximum'] = max(output_list) + output_dictionary['length'] = len(output_list) + return output_dictionary + +input_list = {1, 2, 3, 4} +# Calling the function to get the sumtoatl, average, minimum, maximum and length of the list +output_dictionary = ultimateanalyze(input_list) +print(output_dictionary) + #ReverseList - Create a function that takes a list as a argument and return a list in a reversed order. Do this without creating a empty temporary list. For example #reverse([1,2,3,4]) should return [4,3,2,1]. This challenge is known to appear during basic technical interviews. +# Function to reverse the list +def reverselist(output_list): + return output_list.reverse() + +input_list = [1, 2, 3, 4] +# Calling the function to reverse the list +reverselist(input_list) +print(input_list) + #Ispalindrome- Given a string, write a python function to check if it is palindrome or not. A string is said to be palindrome if the reverse of the string is the same as string. For example, “radar” is a palindrome, but “radix” is not a palindrome. +# Function to check whether the given string is a palindrome or not +def ispalindrome(output_string): + # Checking if the reverse of the string matches the string + if output_string == output_string[::-1]: + return True + else: + return False +input_string = "radar" +# Calling the function to check whether the given string is a palindrome or not +print(ispalindrome(input_string)) + #Fizzbuzz- Create a function that will print numbers from 1 to 100, with certain exceptions: #If the number is a multiple of 3, print “Fizz” instead of the number. #If the number is a multiple of 5, print “Buzz” instead of the number. #If the number is a multiple of 3 and 5, print “FizzBuzz” instead of the number. +# Function to check the multiples of 3, 5 or both and print accordingly print Fizz, Buzz or FizzBuzz +def fizzbuzz(): + for number in range(1, 101): + # Checking if the number is both multiple of 3 and 5 + if number % 3 == 0 and number % 5 == 0: + print("FizzBuzz") + # Checking if the number is a multiple of 3 + elif number % 3 == 0: + print("Fizz") + # Checking if the number is a multiple of 5 + elif number % 5 == 0: + print("Buzz") + else: + print(number) + +# Calling the function to print the numbers from 1 to 100 checking the multiples +fizzbuzz() + + #Fibonacci- The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, #starting from 0 and 1. That is, #F(0) = 0, F(1) = 1 #F(n) = F(n - 1) + F(n - 2), for n > 1. - #Create a function that accepts any number and will create a sequence based on the fibonacci sequence. \ No newline at end of file + #Create a function that accepts any number and will create a sequence based on the fibonacci sequence. + +# Function to get the fibonacci sequence for the given number +def fibonacci(n): + # Initializing the first two number in the fibonacci sequence to zero and one + first_number = 0 + second_number = 1 + + # Assigning 0 if the number is zero + if n == 0: + print(first_number, end = " ") + + # Assigning 1 if the number is 1 + elif n == 1: + print(second_number, end = " ") + else: + number = 0 + # Looping till the length of the given number + while number < n: + print(first_number, end = " ") + temp = first_number + second_number + first_number = second_number + second_number = temp + number += 1 + +# Calling the fibonacci function to print the fibonacci sequence +fibonacci(10) diff --git a/12_12_python.py b/12_12_python.py new file mode 100644 index 0000000..4015fd0 --- /dev/null +++ b/12_12_python.py @@ -0,0 +1,95 @@ +#Create a generator, primes_gen that generates prime numbers starting from 2. +############################################################################# +# Generator Excercises +############################################################################# + +# Generator function to generate prime numbers till 30 +def primes_gen(): + # Looping through numbers from 2 to 30 + for prime in range(2,30): + for number in range(2,prime): + # Checking if the number is prime + if prime%number==0: + break + else: + yield prime + +gen = primes_gen() +for _ in range(10): + print(next(gen), end=' ') + + +# Create a generator, unique_letters that generates unique letters from +# the input string. It should generate the letters in the same order as +# from the input string. +#Function to generate unique letters from a given string +def unique_letters(text): + str = "" + #Looping through the string + for i in text: + #Checking if the letter is not in the result string + if i not in str: + #Concatenating to the result string if it is the first occurence of the letter in the input string + str += i + yield str + +for letter in unique_letters('hello'): + print(letter, end=' ') + +############################################################################# +# Lambda Excercises +############################################################################# + +# # Sort the list by each language's version in ascending order. +prog_lang = [('Python', 3.8), ('Java', 13), ('Javascript', 2019), ('Scala', 2.13)] +prog_lang.sort(key=lambda x: x[1]) +print(prog_lang) + +# Sort the list by the length of the name of each language in descending order. +#prog_lang = [('Python', 3.8), ('Java', 13), ('Javascript', 2019), ('Scala', 2.13)] +prog_lang = [('Python', 3.8), +('Java', 13), +('JavaScript', 2019), +('Scala', 2.13)] +prog_lang.sort(key=lambda x: len(x[0]), reverse = True) +print(prog_lang) + +# Filter the list so that it only contains languages with 'a' in it. +#filter_list = list(filter(lambda x: 'a' in x[0]), prog_lang) +prog_lang = [('Python', 3.8), +('Java', 13), +('JavaScript', 2019), +('Scala', 2.13)] +print(list(filter(lambda x: 'a' in x[0], prog_lang))) + + +#Filter the list so that it only contains languages whose version is in integer +#form. +prog_lang = [('Python', 3.8), +('Java', 13), +('JavaScript', 2019), +('Scala', 2.13)] +# Filtering the version with only integers +print(list(filter(lambda x: type(x[1])==int,prog_lang))) + +# Transform the list so that it contains the tuples in the form, +# ("language in all lower case", length of the language string) +prog_lang = [('Python', 3.8), +('Java', 13), +('JavaScript', 2019), +('Scala', 2.13)] +print(list(map(lambda x: (x[0].lower(),len(x[0])),prog_lang))) + +#Generate a tuple in the form, +#("All languages separated by commas", +#"All versions separated by commas") +prog_lang = [('Python', 3.8), + ('Java', 13), + ('JavaScript', 2019), + ('Scala', 2.13)] +all_languages = tuple(map(lambda x: (x[0]), prog_lang)) +all_versions = tuple(map(lambda x : (str(x[1])),prog_lang)) +# Joining all the languages by commas and all the versions by comma +print((','.join(all_languages),','.join(all_versions))) + + diff --git a/12_13_practice_closure_and_decorators.py b/12_13_practice_closure_and_decorators.py new file mode 100644 index 0000000..8662bf8 --- /dev/null +++ b/12_13_practice_closure_and_decorators.py @@ -0,0 +1,161 @@ +############################################################################# +# Closure Exercise +############################################################################# + +# Using a closure, create a function, multiples_of(n) which we can use to +# create generators that generate multiples of n less than a given +# number. +# Function to get multiples for a given number +def multiples_of(n): + # Function to get multiples for a given number until the product + # is less than the given number + def multiple(k): + for i in range(1, (k//n) + 1): + # Checking if the product is less than the given number + if i*n < k: + yield i * n + + return multiple + +m3 = multiples_of(3) +m3_under30 = m3(30) +m7_under30 = multiples_of(7)(30) + +print(type(m3_under30)) +# output: + +print(*m3_under30) +# output: 3 6 9 12 15 18 21 24 27 + +print(*m7_under30) +# output: 7 14 21 28 + +############################################################################# +# Decorator Exercise +############################################################################# + +# Create following decorators: +# 1. make_upper – make every letter of a string returned from the decorated +# function uppercase. + +def make_upper(func): + def wrapper(): + return func().upper() + return wrapper + +@make_upper +def hello_world(): + return 'hello young, good day!!' + +print(hello_world()) # output: HELLO YOUNG, GOOD DAY!! + +# print_func_name – print the name of the decorated function before +# executing the function. + +def print_func_name(func): + def wrapper(): + print(func.__name__ + ' ' + 'is running...') + return func() + return wrapper + +@print_func_name +def my_func(): + print('Python is fun!!') + +my_func() # output: my_func is running... + # Python is fun + + +# give_name(name) – concatenate the given name at the end of a string +# returned from the decorated function. + +def give_name(n): + def inner(func): + def wrapper(): + return (func() + ' ' + n) + return wrapper + return inner + +@give_name('Theresa') +def greeting(): + return 'Hello' + +print(greeting()) # output: Hello Theresa + + +#print_input_type – print a data type of the input argument before +#executing the decorated function. + +def print_input_type(func): + def wrapper(n): + print('The input data type is ' + str(type(func(n)))) + return (func(n)) + return wrapper + + +@print_input_type +def square(n): + return n ** 2 + +print(square(3.5)) # output: The input data type is + + +# 5. check_return_type(return_type) – check if the return type of the +# decorated function is return_type and print the result before executing +# the function. + +def check_return_type(dtype): + def inner(func): + def wrapper(a): + if type(a) != dtype: + print("=========Error!!\n =========The return type is NOT {}".format(dtype)) + elif type(a) == dtype: + print("The output data type is {}".format(dtype)) + return func(a) + return wrapper + return inner + +@check_return_type(str) +def square(n): + return n ** 2 + +print(square(6)) # output: =========Error!! + #=========The return type is NOT + #36 + +@check_return_type(float) +def square(n): + return n ** 2 + +print(square(2.9)) # output: The return type is + # 8.41 + + + +# execute_log – write a function execution log on the log file. +# function_execution.log +from datetime import datetime, timezone + +def execute_log(func): + def wrapper(*args, **kwargs): + dtime = datetime.now() + result = func(*args, **kwargs) + return ('{0} {1} {2}'.format(dtime,func.__name__,result)) + return wrapper + + +@execute_log +def multiply(*nums): + mult = 1 + for n in nums: + mult *= n + return mult + +@execute_log +def hello_world(): + return 'hello world!!' + +print(multiply(6, 2, 3)) # 36 +print(hello_world()) # hello world!! +print(multiply(2.2, 4)) # 8.8 +print(hello_world()) # hello world!! diff --git a/Data_Analytics_Projects.ipynb b/Data_Analytics_Projects.ipynb new file mode 100644 index 0000000..8d8bbc3 --- /dev/null +++ b/Data_Analytics_Projects.ipynb @@ -0,0 +1,6607 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "cc5c68e3", + "metadata": {}, + "source": [ + "# Real Time Projects" + ] + }, + { + "cell_type": "markdown", + "id": "6379b5ef", + "metadata": {}, + "source": [ + "## The Weather Dataset" + ] + }, + { + "cell_type": "markdown", + "id": "3d6ec4bf", + "metadata": {}, + "source": [ + "Here, The Weather Dataset is a time-series data set with per-hour information about the weather conditions at a particular loacation. It records Tempertaure,\n", + "Dew Point Temperature, Relative Humidity, Wind Speed, Visibility, Pressure, and Conditions.\n", + "\n", + "This data is available as a CSV file. We are going to analyze this data set using the Pandas DataFrame." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "9e2e44fe", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Defaulting to user installation because normal site-packages is not writeable\n", + "Requirement already satisfied: pandas in c:\\users\\anand\\appdata\\roaming\\python\\python311\\site-packages (1.5.2)\n", + "Requirement already satisfied: python-dateutil>=2.8.1 in c:\\program files\\python311\\lib\\site-packages (from pandas) (2.8.2)\n", + "Requirement already satisfied: pytz>=2020.1 in c:\\program files\\python311\\lib\\site-packages (from pandas) (2022.6)\n", + "Requirement already satisfied: numpy>=1.21.0 in c:\\users\\anand\\appdata\\roaming\\python\\python311\\site-packages (from pandas) (1.24.1)\n", + "Requirement already satisfied: six>=1.5 in c:\\program files\\python311\\lib\\site-packages (from python-dateutil>=2.8.1->pandas) (1.16.0)\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "pip install pandas" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "017a67df", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "44695be3", + "metadata": {}, + "outputs": [], + "source": [ + "data = pd.read_csv(r\"C:\\Users\\anand\\Downloads\\1. Weather Data.csv\")" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "2c7983a7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Date/TimeTemp_CDew Point Temp_CRel Hum_%Wind Speed_km/hVisibility_kmPress_kPaWeather
01/1/2012 0:00-1.8-3.98648.0101.24Fog
11/1/2012 1:00-1.8-3.78748.0101.24Fog
21/1/2012 2:00-1.8-3.48974.0101.26Freezing Drizzle,Fog
31/1/2012 3:00-1.5-3.28864.0101.27Freezing Drizzle,Fog
41/1/2012 4:00-1.5-3.38874.8101.23Fog
...........................
877912/31/2012 19:000.1-2.781309.7100.13Snow
878012/31/2012 20:000.2-2.483249.7100.03Snow
878112/31/2012 21:00-0.5-1.593284.899.95Snow
878212/31/2012 22:00-0.2-1.889289.799.91Snow
878312/31/2012 23:000.0-2.1863011.399.89Snow
\n", + "

8784 rows × 8 columns

\n", + "
" + ], + "text/plain": [ + " Date/Time Temp_C Dew Point Temp_C Rel Hum_% Wind Speed_km/h \\\n", + "0 1/1/2012 0:00 -1.8 -3.9 86 4 \n", + "1 1/1/2012 1:00 -1.8 -3.7 87 4 \n", + "2 1/1/2012 2:00 -1.8 -3.4 89 7 \n", + "3 1/1/2012 3:00 -1.5 -3.2 88 6 \n", + "4 1/1/2012 4:00 -1.5 -3.3 88 7 \n", + "... ... ... ... ... ... \n", + "8779 12/31/2012 19:00 0.1 -2.7 81 30 \n", + "8780 12/31/2012 20:00 0.2 -2.4 83 24 \n", + "8781 12/31/2012 21:00 -0.5 -1.5 93 28 \n", + "8782 12/31/2012 22:00 -0.2 -1.8 89 28 \n", + "8783 12/31/2012 23:00 0.0 -2.1 86 30 \n", + "\n", + " Visibility_km Press_kPa Weather \n", + "0 8.0 101.24 Fog \n", + "1 8.0 101.24 Fog \n", + "2 4.0 101.26 Freezing Drizzle,Fog \n", + "3 4.0 101.27 Freezing Drizzle,Fog \n", + "4 4.8 101.23 Fog \n", + "... ... ... ... \n", + "8779 9.7 100.13 Snow \n", + "8780 9.7 100.03 Snow \n", + "8781 4.8 99.95 Snow \n", + "8782 9.7 99.91 Snow \n", + "8783 11.3 99.89 Snow \n", + "\n", + "[8784 rows x 8 columns]" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data" + ] + }, + { + "cell_type": "markdown", + "id": "36f7b224", + "metadata": {}, + "source": [ + "# How to Analyze DataFrames?" + ] + }, + { + "cell_type": "markdown", + "id": "3f622526", + "metadata": {}, + "source": [ + "## .head()" + ] + }, + { + "cell_type": "markdown", + "id": "3e9facea", + "metadata": {}, + "source": [ + "It shows the first N rows in the data (by default, N=5)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "12125c1e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Date/TimeTemp_CDew Point Temp_CRel Hum_%Wind Speed_km/hVisibility_kmPress_kPaWeather
01/1/2012 0:00-1.8-3.98648.0101.24Fog
11/1/2012 1:00-1.8-3.78748.0101.24Fog
21/1/2012 2:00-1.8-3.48974.0101.26Freezing Drizzle,Fog
31/1/2012 3:00-1.5-3.28864.0101.27Freezing Drizzle,Fog
41/1/2012 4:00-1.5-3.38874.8101.23Fog
\n", + "
" + ], + "text/plain": [ + " Date/Time Temp_C Dew Point Temp_C Rel Hum_% Wind Speed_km/h \\\n", + "0 1/1/2012 0:00 -1.8 -3.9 86 4 \n", + "1 1/1/2012 1:00 -1.8 -3.7 87 4 \n", + "2 1/1/2012 2:00 -1.8 -3.4 89 7 \n", + "3 1/1/2012 3:00 -1.5 -3.2 88 6 \n", + "4 1/1/2012 4:00 -1.5 -3.3 88 7 \n", + "\n", + " Visibility_km Press_kPa Weather \n", + "0 8.0 101.24 Fog \n", + "1 8.0 101.24 Fog \n", + "2 4.0 101.26 Freezing Drizzle,Fog \n", + "3 4.0 101.27 Freezing Drizzle,Fog \n", + "4 4.8 101.23 Fog " + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.head()" + ] + }, + { + "cell_type": "markdown", + "id": "a292e315", + "metadata": {}, + "source": [ + "## .shape" + ] + }, + { + "cell_type": "markdown", + "id": "abcfd240", + "metadata": {}, + "source": [ + "It shows the total no. of rows and no. of columns of the dataframe" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "d67e28df", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(8784, 8)" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.shape" + ] + }, + { + "cell_type": "markdown", + "id": "76d8fffa", + "metadata": {}, + "source": [ + "## .index" + ] + }, + { + "cell_type": "markdown", + "id": "e653ab90", + "metadata": {}, + "source": [ + "This attribute provides the index of the dataframe" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "8b34497a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "RangeIndex(start=0, stop=8784, step=1)" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.index" + ] + }, + { + "cell_type": "markdown", + "id": "ca5659a3", + "metadata": {}, + "source": [ + "## .columns" + ] + }, + { + "cell_type": "markdown", + "id": "8af2b4b0", + "metadata": {}, + "source": [ + "It shows the data-type of each column" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "eb5ac67f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Index(['Date/Time', 'Temp_C', 'Dew Point Temp_C', 'Rel Hum_%',\n", + " 'Wind Speed_km/h', 'Visibility_km', 'Press_kPa', 'Weather'],\n", + " dtype='object')" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.columns" + ] + }, + { + "cell_type": "markdown", + "id": "53d86364", + "metadata": {}, + "source": [ + "## .dtypes" + ] + }, + { + "cell_type": "markdown", + "id": "dec3d0d2", + "metadata": {}, + "source": [ + "It shows the data-type of each column" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "ba5f1c3d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Date/Time object\n", + "Temp_C float64\n", + "Dew Point Temp_C float64\n", + "Rel Hum_% int64\n", + "Wind Speed_km/h int64\n", + "Visibility_km float64\n", + "Press_kPa float64\n", + "Weather object\n", + "dtype: object" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.dtypes" + ] + }, + { + "cell_type": "markdown", + "id": "a0219ecb", + "metadata": {}, + "source": [ + "## .unique()" + ] + }, + { + "cell_type": "markdown", + "id": "1d99a57d", + "metadata": {}, + "source": [ + "In a column. It shows all the unique values. It can be applied on a single column only, not on the whole dataframe." + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "aed5dc7b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array(['Fog', 'Freezing Drizzle,Fog', 'Mostly Cloudy', 'Cloudy', 'Rain',\n", + " 'Rain Showers', 'Mainly Clear', 'Snow Showers', 'Snow', 'Clear',\n", + " 'Freezing Rain,Fog', 'Freezing Rain', 'Freezing Drizzle',\n", + " 'Rain,Snow', 'Moderate Snow', 'Freezing Drizzle,Snow',\n", + " 'Freezing Rain,Snow Grains', 'Snow,Blowing Snow', 'Freezing Fog',\n", + " 'Haze', 'Rain,Fog', 'Drizzle,Fog', 'Drizzle',\n", + " 'Freezing Drizzle,Haze', 'Freezing Rain,Haze', 'Snow,Haze',\n", + " 'Snow,Fog', 'Snow,Ice Pellets', 'Rain,Haze', 'Thunderstorms,Rain',\n", + " 'Thunderstorms,Rain Showers', 'Thunderstorms,Heavy Rain Showers',\n", + " 'Thunderstorms,Rain Showers,Fog', 'Thunderstorms',\n", + " 'Thunderstorms,Rain,Fog',\n", + " 'Thunderstorms,Moderate Rain Showers,Fog', 'Rain Showers,Fog',\n", + " 'Rain Showers,Snow Showers', 'Snow Pellets', 'Rain,Snow,Fog',\n", + " 'Moderate Rain,Fog', 'Freezing Rain,Ice Pellets,Fog',\n", + " 'Drizzle,Ice Pellets,Fog', 'Drizzle,Snow', 'Rain,Ice Pellets',\n", + " 'Drizzle,Snow,Fog', 'Rain,Snow Grains', 'Rain,Snow,Ice Pellets',\n", + " 'Snow Showers,Fog', 'Moderate Snow,Blowing Snow'], dtype=object)" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data['Weather'].unique()" + ] + }, + { + "cell_type": "markdown", + "id": "1fad9023", + "metadata": {}, + "source": [ + "## .nunique()" + ] + }, + { + "cell_type": "markdown", + "id": "bb962c53", + "metadata": {}, + "source": [ + "It shows the total no. of unique values in each column. It can be applied on a single columns well as on whole dataframe." + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "bade5ee9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Date/Time 8784\n", + "Temp_C 533\n", + "Dew Point Temp_C 489\n", + "Rel Hum_% 83\n", + "Wind Speed_km/h 34\n", + "Visibility_km 24\n", + "Press_kPa 518\n", + "Weather 50\n", + "dtype: int64" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.nunique()" + ] + }, + { + "cell_type": "markdown", + "id": "d6a6ca6a", + "metadata": {}, + "source": [ + "## .count" + ] + }, + { + "cell_type": "markdown", + "id": "ab7d37d4", + "metadata": {}, + "source": [ + "It shows the total no. of non-null values in each column. It can be applied on a single column as well as on whole dataframe." + ] + }, + { + "cell_type": "markdown", + "id": "017dd662", + "metadata": {}, + "source": [ + "## .value_counts" + ] + }, + { + "cell_type": "markdown", + "id": "79bbd63c", + "metadata": {}, + "source": [ + "In a column, it shows all the unique values with their count. It can be applied on single column only." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "8d208b4c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Mainly Clear 2106\n", + "Mostly Cloudy 2069\n", + "Cloudy 1728\n", + "Clear 1326\n", + "Snow 390\n", + "Rain 306\n", + "Rain Showers 188\n", + "Fog 150\n", + "Rain,Fog 116\n", + "Drizzle,Fog 80\n", + "Snow Showers 60\n", + "Drizzle 41\n", + "Snow,Fog 37\n", + "Snow,Blowing Snow 19\n", + "Rain,Snow 18\n", + "Thunderstorms,Rain Showers 16\n", + "Haze 16\n", + "Drizzle,Snow,Fog 15\n", + "Freezing Rain 14\n", + "Freezing Drizzle,Snow 11\n", + "Freezing Drizzle 7\n", + "Snow,Ice Pellets 6\n", + "Freezing Drizzle,Fog 6\n", + "Snow,Haze 5\n", + "Freezing Fog 4\n", + "Snow Showers,Fog 4\n", + "Moderate Snow 4\n", + "Rain,Snow,Ice Pellets 4\n", + "Freezing Rain,Fog 4\n", + "Freezing Drizzle,Haze 3\n", + "Rain,Haze 3\n", + "Thunderstorms,Rain 3\n", + "Thunderstorms,Rain Showers,Fog 3\n", + "Freezing Rain,Haze 2\n", + "Drizzle,Snow 2\n", + "Rain Showers,Snow Showers 2\n", + "Thunderstorms 2\n", + "Moderate Snow,Blowing Snow 2\n", + "Rain Showers,Fog 1\n", + "Thunderstorms,Moderate Rain Showers,Fog 1\n", + "Snow Pellets 1\n", + "Rain,Snow,Fog 1\n", + "Moderate Rain,Fog 1\n", + "Freezing Rain,Ice Pellets,Fog 1\n", + "Drizzle,Ice Pellets,Fog 1\n", + "Thunderstorms,Rain,Fog 1\n", + "Rain,Ice Pellets 1\n", + "Rain,Snow Grains 1\n", + "Thunderstorms,Heavy Rain Showers 1\n", + "Freezing Rain,Snow Grains 1\n", + "Name: Weather, dtype: int64" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data['Weather'].value_counts()" + ] + }, + { + "cell_type": "markdown", + "id": "f8195241", + "metadata": {}, + "source": [ + "## .info()" + ] + }, + { + "cell_type": "markdown", + "id": "ff4d16ff", + "metadata": {}, + "source": [ + "Provides basic information about the dataframe." + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "4e1350f7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "RangeIndex: 8784 entries, 0 to 8783\n", + "Data columns (total 8 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 Date/Time 8784 non-null object \n", + " 1 Temp_C 8784 non-null float64\n", + " 2 Dew Point Temp_C 8784 non-null float64\n", + " 3 Rel Hum_% 8784 non-null int64 \n", + " 4 Wind Speed_km/h 8784 non-null int64 \n", + " 5 Visibility_km 8784 non-null float64\n", + " 6 Press_kPa 8784 non-null float64\n", + " 7 Weather 8784 non-null object \n", + "dtypes: float64(4), int64(2), object(2)\n", + "memory usage: 549.1+ KB\n" + ] + } + ], + "source": [ + "data.info()" + ] + }, + { + "cell_type": "markdown", + "id": "886c12dd", + "metadata": {}, + "source": [ + "## Q) 1. Find all the unique 'Wind Speed' values in the data." + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "b02135f9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Date/TimeTemp_CDew Point Temp_CRel Hum_%Wind Speed_km/hVisibility_kmPress_kPaWeather
01/1/2012 0:00-1.8-3.98648.0101.24Fog
11/1/2012 1:00-1.8-3.78748.0101.24Fog
\n", + "
" + ], + "text/plain": [ + " Date/Time Temp_C Dew Point Temp_C Rel Hum_% Wind Speed_km/h \\\n", + "0 1/1/2012 0:00 -1.8 -3.9 86 4 \n", + "1 1/1/2012 1:00 -1.8 -3.7 87 4 \n", + "\n", + " Visibility_km Press_kPa Weather \n", + "0 8.0 101.24 Fog \n", + "1 8.0 101.24 Fog " + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.head(2)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "db59df36", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Date/Time 8784\n", + "Temp_C 533\n", + "Dew Point Temp_C 489\n", + "Rel Hum_% 83\n", + "Wind Speed_km/h 34\n", + "Visibility_km 24\n", + "Press_kPa 518\n", + "Weather 50\n", + "dtype: int64" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.nunique()" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "2ec63db2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "34" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data['Wind Speed_km/h'].nunique()" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "9390df93", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([ 4, 7, 6, 9, 15, 13, 20, 22, 19, 24, 30, 35, 39, 32, 33, 26, 44,\n", + " 43, 48, 37, 28, 17, 11, 0, 83, 70, 57, 46, 41, 52, 50, 63, 54, 2],\n", + " dtype=int64)" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data['Wind Speed_km/h'].unique()" + ] + }, + { + "cell_type": "markdown", + "id": "7540add3", + "metadata": {}, + "source": [ + "## Q) 2. Find the number of times when the 'Weather is exactly Clear'." + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "fec0b6c2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Date/TimeTemp_CDew Point Temp_CRel Hum_%Wind Speed_km/hVisibility_kmPress_kPaWeather
01/1/2012 0:00-1.8-3.98648.0101.24Fog
11/1/2012 1:00-1.8-3.78748.0101.24Fog
\n", + "
" + ], + "text/plain": [ + " Date/Time Temp_C Dew Point Temp_C Rel Hum_% Wind Speed_km/h \\\n", + "0 1/1/2012 0:00 -1.8 -3.9 86 4 \n", + "1 1/1/2012 1:00 -1.8 -3.7 87 4 \n", + "\n", + " Visibility_km Press_kPa Weather \n", + "0 8.0 101.24 Fog \n", + "1 8.0 101.24 Fog " + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.head(2)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "cca80a58", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Mainly Clear 2106\n", + "Mostly Cloudy 2069\n", + "Cloudy 1728\n", + "Clear 1326\n", + "Snow 390\n", + "Rain 306\n", + "Rain Showers 188\n", + "Fog 150\n", + "Rain,Fog 116\n", + "Drizzle,Fog 80\n", + "Snow Showers 60\n", + "Drizzle 41\n", + "Snow,Fog 37\n", + "Snow,Blowing Snow 19\n", + "Rain,Snow 18\n", + "Thunderstorms,Rain Showers 16\n", + "Haze 16\n", + "Drizzle,Snow,Fog 15\n", + "Freezing Rain 14\n", + "Freezing Drizzle,Snow 11\n", + "Freezing Drizzle 7\n", + "Snow,Ice Pellets 6\n", + "Freezing Drizzle,Fog 6\n", + "Snow,Haze 5\n", + "Freezing Fog 4\n", + "Snow Showers,Fog 4\n", + "Moderate Snow 4\n", + "Rain,Snow,Ice Pellets 4\n", + "Freezing Rain,Fog 4\n", + "Freezing Drizzle,Haze 3\n", + "Rain,Haze 3\n", + "Thunderstorms,Rain 3\n", + "Thunderstorms,Rain Showers,Fog 3\n", + "Freezing Rain,Haze 2\n", + "Drizzle,Snow 2\n", + "Rain Showers,Snow Showers 2\n", + "Thunderstorms 2\n", + "Moderate Snow,Blowing Snow 2\n", + "Rain Showers,Fog 1\n", + "Thunderstorms,Moderate Rain Showers,Fog 1\n", + "Snow Pellets 1\n", + "Rain,Snow,Fog 1\n", + "Moderate Rain,Fog 1\n", + "Freezing Rain,Ice Pellets,Fog 1\n", + "Drizzle,Ice Pellets,Fog 1\n", + "Thunderstorms,Rain,Fog 1\n", + "Rain,Ice Pellets 1\n", + "Rain,Snow Grains 1\n", + "Thunderstorms,Heavy Rain Showers 1\n", + "Freezing Rain,Snow Grains 1\n", + "Name: Weather, dtype: int64" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.Weather.value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "c2395747", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Date/TimeTemp_CDew Point Temp_CRel Hum_%Wind Speed_km/hVisibility_kmPress_kPaWeather
671/3/2012 19:00-16.9-24.8502425.0101.74Clear
1141/5/2012 18:00-7.1-14.4561125.0100.71Clear
1151/5/2012 19:00-9.2-15.461725.0100.80Clear
1161/5/2012 20:00-9.8-15.762925.0100.83Clear
1171/5/2012 21:00-9.0-14.8631325.0100.83Clear
...........................
864612/26/2012 6:00-13.4-14.889425.0102.47Clear
869812/28/2012 10:00-6.1-8.6821924.1101.27Clear
871312/29/2012 1:00-11.9-13.6871125.0101.31Clear
871412/29/2012 2:00-11.8-13.1901325.0101.33Clear
875612/30/2012 20:00-13.8-16.5802425.0101.52Clear
\n", + "

1326 rows × 8 columns

\n", + "
" + ], + "text/plain": [ + " Date/Time Temp_C Dew Point Temp_C Rel Hum_% Wind Speed_km/h \\\n", + "67 1/3/2012 19:00 -16.9 -24.8 50 24 \n", + "114 1/5/2012 18:00 -7.1 -14.4 56 11 \n", + "115 1/5/2012 19:00 -9.2 -15.4 61 7 \n", + "116 1/5/2012 20:00 -9.8 -15.7 62 9 \n", + "117 1/5/2012 21:00 -9.0 -14.8 63 13 \n", + "... ... ... ... ... ... \n", + "8646 12/26/2012 6:00 -13.4 -14.8 89 4 \n", + "8698 12/28/2012 10:00 -6.1 -8.6 82 19 \n", + "8713 12/29/2012 1:00 -11.9 -13.6 87 11 \n", + "8714 12/29/2012 2:00 -11.8 -13.1 90 13 \n", + "8756 12/30/2012 20:00 -13.8 -16.5 80 24 \n", + "\n", + " Visibility_km Press_kPa Weather \n", + "67 25.0 101.74 Clear \n", + "114 25.0 100.71 Clear \n", + "115 25.0 100.80 Clear \n", + "116 25.0 100.83 Clear \n", + "117 25.0 100.83 Clear \n", + "... ... ... ... \n", + "8646 25.0 102.47 Clear \n", + "8698 24.1 101.27 Clear \n", + "8713 25.0 101.31 Clear \n", + "8714 25.0 101.33 Clear \n", + "8756 25.0 101.52 Clear \n", + "\n", + "[1326 rows x 8 columns]" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Filtering\n", + "data[data.Weather == 'Clear']" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "2886c656", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Date/TimeTemp_CDew Point Temp_CRel Hum_%Wind Speed_km/hVisibility_kmPress_kPaWeather
671/3/2012 19:00-16.9-24.8502425.0101.74Clear
1141/5/2012 18:00-7.1-14.4561125.0100.71Clear
1151/5/2012 19:00-9.2-15.461725.0100.80Clear
1161/5/2012 20:00-9.8-15.762925.0100.83Clear
1171/5/2012 21:00-9.0-14.8631325.0100.83Clear
...........................
864612/26/2012 6:00-13.4-14.889425.0102.47Clear
869812/28/2012 10:00-6.1-8.6821924.1101.27Clear
871312/29/2012 1:00-11.9-13.6871125.0101.31Clear
871412/29/2012 2:00-11.8-13.1901325.0101.33Clear
875612/30/2012 20:00-13.8-16.5802425.0101.52Clear
\n", + "

1326 rows × 8 columns

\n", + "
" + ], + "text/plain": [ + " Date/Time Temp_C Dew Point Temp_C Rel Hum_% Wind Speed_km/h \\\n", + "67 1/3/2012 19:00 -16.9 -24.8 50 24 \n", + "114 1/5/2012 18:00 -7.1 -14.4 56 11 \n", + "115 1/5/2012 19:00 -9.2 -15.4 61 7 \n", + "116 1/5/2012 20:00 -9.8 -15.7 62 9 \n", + "117 1/5/2012 21:00 -9.0 -14.8 63 13 \n", + "... ... ... ... ... ... \n", + "8646 12/26/2012 6:00 -13.4 -14.8 89 4 \n", + "8698 12/28/2012 10:00 -6.1 -8.6 82 19 \n", + "8713 12/29/2012 1:00 -11.9 -13.6 87 11 \n", + "8714 12/29/2012 2:00 -11.8 -13.1 90 13 \n", + "8756 12/30/2012 20:00 -13.8 -16.5 80 24 \n", + "\n", + " Visibility_km Press_kPa Weather \n", + "67 25.0 101.74 Clear \n", + "114 25.0 100.71 Clear \n", + "115 25.0 100.80 Clear \n", + "116 25.0 100.83 Clear \n", + "117 25.0 100.83 Clear \n", + "... ... ... ... \n", + "8646 25.0 102.47 Clear \n", + "8698 24.1 101.27 Clear \n", + "8713 25.0 101.31 Clear \n", + "8714 25.0 101.33 Clear \n", + "8756 25.0 101.52 Clear \n", + "\n", + "[1326 rows x 8 columns]" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# groupby()\n", + "data.groupby('Weather').get_group('Clear')" + ] + }, + { + "cell_type": "markdown", + "id": "8cabff3f", + "metadata": {}, + "source": [ + "## Q) 3. Find the number of times when the 'Wind Speed was exactly 4 km/h'." + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "f30cdeca", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Date/TimeTemp_CDew Point Temp_CRel Hum_%Wind Speed_km/hVisibility_kmPress_kPaWeather
01/1/2012 0:00-1.8-3.98648.0101.24Fog
11/1/2012 1:00-1.8-3.78748.0101.24Fog
961/5/2012 0:00-8.8-11.77949.7100.32Snow
1011/5/2012 5:00-7.0-9.58244.0100.19Snow
1461/7/2012 2:00-8.1-11.179419.3100.15Cloudy
...........................
876812/31/2012 8:00-8.6-10.38743.2101.14Snow Showers
876912/31/2012 9:00-8.1-9.68942.4101.09Snow
877012/31/2012 10:00-7.4-8.98946.4101.05Snow,Fog
877212/31/2012 12:00-5.8-7.588412.9100.78Snow
877312/31/2012 13:00-4.6-6.686412.9100.63Snow
\n", + "

474 rows × 8 columns

\n", + "
" + ], + "text/plain": [ + " Date/Time Temp_C Dew Point Temp_C Rel Hum_% Wind Speed_km/h \\\n", + "0 1/1/2012 0:00 -1.8 -3.9 86 4 \n", + "1 1/1/2012 1:00 -1.8 -3.7 87 4 \n", + "96 1/5/2012 0:00 -8.8 -11.7 79 4 \n", + "101 1/5/2012 5:00 -7.0 -9.5 82 4 \n", + "146 1/7/2012 2:00 -8.1 -11.1 79 4 \n", + "... ... ... ... ... ... \n", + "8768 12/31/2012 8:00 -8.6 -10.3 87 4 \n", + "8769 12/31/2012 9:00 -8.1 -9.6 89 4 \n", + "8770 12/31/2012 10:00 -7.4 -8.9 89 4 \n", + "8772 12/31/2012 12:00 -5.8 -7.5 88 4 \n", + "8773 12/31/2012 13:00 -4.6 -6.6 86 4 \n", + "\n", + " Visibility_km Press_kPa Weather \n", + "0 8.0 101.24 Fog \n", + "1 8.0 101.24 Fog \n", + "96 9.7 100.32 Snow \n", + "101 4.0 100.19 Snow \n", + "146 19.3 100.15 Cloudy \n", + "... ... ... ... \n", + "8768 3.2 101.14 Snow Showers \n", + "8769 2.4 101.09 Snow \n", + "8770 6.4 101.05 Snow,Fog \n", + "8772 12.9 100.78 Snow \n", + "8773 12.9 100.63 Snow \n", + "\n", + "[474 rows x 8 columns]" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data[data['Wind Speed_km/h'] == 4]" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "5bd0a9ac", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Date/TimeTemp_CDew Point Temp_CRel Hum_%Wind Speed_km/hVisibility_kmPress_kPaWeather
01/1/2012 0:00-1.8-3.98648.0101.24Fog
11/1/2012 1:00-1.8-3.78748.0101.24Fog
961/5/2012 0:00-8.8-11.77949.7100.32Snow
1011/5/2012 5:00-7.0-9.58244.0100.19Snow
1461/7/2012 2:00-8.1-11.179419.3100.15Cloudy
...........................
876812/31/2012 8:00-8.6-10.38743.2101.14Snow Showers
876912/31/2012 9:00-8.1-9.68942.4101.09Snow
877012/31/2012 10:00-7.4-8.98946.4101.05Snow,Fog
877212/31/2012 12:00-5.8-7.588412.9100.78Snow
877312/31/2012 13:00-4.6-6.686412.9100.63Snow
\n", + "

474 rows × 8 columns

\n", + "
" + ], + "text/plain": [ + " Date/Time Temp_C Dew Point Temp_C Rel Hum_% Wind Speed_km/h \\\n", + "0 1/1/2012 0:00 -1.8 -3.9 86 4 \n", + "1 1/1/2012 1:00 -1.8 -3.7 87 4 \n", + "96 1/5/2012 0:00 -8.8 -11.7 79 4 \n", + "101 1/5/2012 5:00 -7.0 -9.5 82 4 \n", + "146 1/7/2012 2:00 -8.1 -11.1 79 4 \n", + "... ... ... ... ... ... \n", + "8768 12/31/2012 8:00 -8.6 -10.3 87 4 \n", + "8769 12/31/2012 9:00 -8.1 -9.6 89 4 \n", + "8770 12/31/2012 10:00 -7.4 -8.9 89 4 \n", + "8772 12/31/2012 12:00 -5.8 -7.5 88 4 \n", + "8773 12/31/2012 13:00 -4.6 -6.6 86 4 \n", + "\n", + " Visibility_km Press_kPa Weather \n", + "0 8.0 101.24 Fog \n", + "1 8.0 101.24 Fog \n", + "96 9.7 100.32 Snow \n", + "101 4.0 100.19 Snow \n", + "146 19.3 100.15 Cloudy \n", + "... ... ... ... \n", + "8768 3.2 101.14 Snow Showers \n", + "8769 2.4 101.09 Snow \n", + "8770 6.4 101.05 Snow,Fog \n", + "8772 12.9 100.78 Snow \n", + "8773 12.9 100.63 Snow \n", + "\n", + "[474 rows x 8 columns]" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# groupby()\n", + "data.groupby('Wind Speed_km/h').get_group(4)" + ] + }, + { + "cell_type": "markdown", + "id": "a47236ea", + "metadata": {}, + "source": [ + "## Q) 4. Find out all the Null Values in the data." + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "2c18c289", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Date/Time 0\n", + "Temp_C 0\n", + "Dew Point Temp_C 0\n", + "Rel Hum_% 0\n", + "Wind Speed_km/h 0\n", + "Visibility_km 0\n", + "Press_kPa 0\n", + "Weather 0\n", + "dtype: int64" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.isnull().sum()" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "7f2c0d23", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Date/Time 8784\n", + "Temp_C 8784\n", + "Dew Point Temp_C 8784\n", + "Rel Hum_% 8784\n", + "Wind Speed_km/h 8784\n", + "Visibility_km 8784\n", + "Press_kPa 8784\n", + "Weather 8784\n", + "dtype: int64" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.notnull().sum()" + ] + }, + { + "cell_type": "markdown", + "id": "e94926b1", + "metadata": {}, + "source": [ + "## Q) 5. Rename the column name 'Weather' of the dataframe to 'Weather Condition'" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "id": "99fcfce7", + "metadata": {}, + "outputs": [], + "source": [ + "data.rename(columns = {'Weather' : 'Weather Condition'}, inplace = True)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "id": "592c9495", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Date/TimeTemp_CDew Point Temp_CRel Hum_%Wind Speed_km/hVisibility_kmPress_kPaWeather Condition
01/1/2012 0:00-1.8-3.98648.0101.24Fog
11/1/2012 1:00-1.8-3.78748.0101.24Fog
21/1/2012 2:00-1.8-3.48974.0101.26Freezing Drizzle,Fog
31/1/2012 3:00-1.5-3.28864.0101.27Freezing Drizzle,Fog
41/1/2012 4:00-1.5-3.38874.8101.23Fog
\n", + "
" + ], + "text/plain": [ + " Date/Time Temp_C Dew Point Temp_C Rel Hum_% Wind Speed_km/h \\\n", + "0 1/1/2012 0:00 -1.8 -3.9 86 4 \n", + "1 1/1/2012 1:00 -1.8 -3.7 87 4 \n", + "2 1/1/2012 2:00 -1.8 -3.4 89 7 \n", + "3 1/1/2012 3:00 -1.5 -3.2 88 6 \n", + "4 1/1/2012 4:00 -1.5 -3.3 88 7 \n", + "\n", + " Visibility_km Press_kPa Weather Condition \n", + "0 8.0 101.24 Fog \n", + "1 8.0 101.24 Fog \n", + "2 4.0 101.26 Freezing Drizzle,Fog \n", + "3 4.0 101.27 Freezing Drizzle,Fog \n", + "4 4.8 101.23 Fog " + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.head()" + ] + }, + { + "cell_type": "markdown", + "id": "9c2c9f09", + "metadata": {}, + "source": [ + "## Q) 6. What is the mean 'Visibility'?" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "e0a22275", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "27.664446721311478" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.Visibility_km.mean()" + ] + }, + { + "cell_type": "markdown", + "id": "8cb106b0", + "metadata": {}, + "source": [ + "## Q) 7. What is the Standard Deviaiton of 'Pressure' in this data?" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "e095752e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.8440047459486483" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.Press_kPa.std()" + ] + }, + { + "cell_type": "markdown", + "id": "9d3a5078", + "metadata": {}, + "source": [ + "## Q) 8. What is the Variance of 'Relative Humidity' in this data?" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "f6a6a7a9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "286.24855019850196" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data['Rel Hum_%'].var()" + ] + }, + { + "cell_type": "markdown", + "id": "ee442022", + "metadata": {}, + "source": [ + "## Q) 9. Find all instances when 'Snow' was recorded." + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "id": "4047d737", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Mainly Clear 2106\n", + "Mostly Cloudy 2069\n", + "Cloudy 1728\n", + "Clear 1326\n", + "Snow 390\n", + "Rain 306\n", + "Rain Showers 188\n", + "Fog 150\n", + "Rain,Fog 116\n", + "Drizzle,Fog 80\n", + "Snow Showers 60\n", + "Drizzle 41\n", + "Snow,Fog 37\n", + "Snow,Blowing Snow 19\n", + "Rain,Snow 18\n", + "Thunderstorms,Rain Showers 16\n", + "Haze 16\n", + "Drizzle,Snow,Fog 15\n", + "Freezing Rain 14\n", + "Freezing Drizzle,Snow 11\n", + "Freezing Drizzle 7\n", + "Snow,Ice Pellets 6\n", + "Freezing Drizzle,Fog 6\n", + "Snow,Haze 5\n", + "Freezing Fog 4\n", + "Snow Showers,Fog 4\n", + "Moderate Snow 4\n", + "Rain,Snow,Ice Pellets 4\n", + "Freezing Rain,Fog 4\n", + "Freezing Drizzle,Haze 3\n", + "Rain,Haze 3\n", + "Thunderstorms,Rain 3\n", + "Thunderstorms,Rain Showers,Fog 3\n", + "Freezing Rain,Haze 2\n", + "Drizzle,Snow 2\n", + "Rain Showers,Snow Showers 2\n", + "Thunderstorms 2\n", + "Moderate Snow,Blowing Snow 2\n", + "Rain Showers,Fog 1\n", + "Thunderstorms,Moderate Rain Showers,Fog 1\n", + "Snow Pellets 1\n", + "Rain,Snow,Fog 1\n", + "Moderate Rain,Fog 1\n", + "Freezing Rain,Ice Pellets,Fog 1\n", + "Drizzle,Ice Pellets,Fog 1\n", + "Thunderstorms,Rain,Fog 1\n", + "Rain,Ice Pellets 1\n", + "Rain,Snow Grains 1\n", + "Thunderstorms,Heavy Rain Showers 1\n", + "Freezing Rain,Snow Grains 1\n", + "Name: Weather Condition, dtype: int64" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#value_counts()\n", + "data['Weather Condition'].value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "id": "876b244c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Date/TimeTemp_CDew Point Temp_CRel Hum_%Wind Speed_km/hVisibility_kmPress_kPaWeather Condition
551/3/2012 7:00-14.0-19.5631925.0100.95Snow
841/4/2012 12:00-13.7-21.7511124.1101.25Snow
861/4/2012 14:00-11.3-19.053719.3100.97Snow
871/4/2012 15:00-10.2-16.361119.7100.89Snow
881/4/2012 16:00-9.4-15.5611319.3100.79Snow
...........................
877912/31/2012 19:000.1-2.781309.7100.13Snow
878012/31/2012 20:000.2-2.483249.7100.03Snow
878112/31/2012 21:00-0.5-1.593284.899.95Snow
878212/31/2012 22:00-0.2-1.889289.799.91Snow
878312/31/2012 23:000.0-2.1863011.399.89Snow
\n", + "

390 rows × 8 columns

\n", + "
" + ], + "text/plain": [ + " Date/Time Temp_C Dew Point Temp_C Rel Hum_% Wind Speed_km/h \\\n", + "55 1/3/2012 7:00 -14.0 -19.5 63 19 \n", + "84 1/4/2012 12:00 -13.7 -21.7 51 11 \n", + "86 1/4/2012 14:00 -11.3 -19.0 53 7 \n", + "87 1/4/2012 15:00 -10.2 -16.3 61 11 \n", + "88 1/4/2012 16:00 -9.4 -15.5 61 13 \n", + "... ... ... ... ... ... \n", + "8779 12/31/2012 19:00 0.1 -2.7 81 30 \n", + "8780 12/31/2012 20:00 0.2 -2.4 83 24 \n", + "8781 12/31/2012 21:00 -0.5 -1.5 93 28 \n", + "8782 12/31/2012 22:00 -0.2 -1.8 89 28 \n", + "8783 12/31/2012 23:00 0.0 -2.1 86 30 \n", + "\n", + " Visibility_km Press_kPa Weather Condition \n", + "55 25.0 100.95 Snow \n", + "84 24.1 101.25 Snow \n", + "86 19.3 100.97 Snow \n", + "87 9.7 100.89 Snow \n", + "88 19.3 100.79 Snow \n", + "... ... ... ... \n", + "8779 9.7 100.13 Snow \n", + "8780 9.7 100.03 Snow \n", + "8781 4.8 99.95 Snow \n", + "8782 9.7 99.91 Snow \n", + "8783 11.3 99.89 Snow \n", + "\n", + "[390 rows x 8 columns]" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Filtering\n", + "data[data['Weather Condition'] == 'Snow']" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "id": "9729bbaf", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Date/TimeTemp_CDew Point Temp_CRel Hum_%Wind Speed_km/hVisibility_kmPress_kPaWeather Condition
551/3/2012 7:00-14.0-19.5631925.0100.95Snow
841/4/2012 12:00-13.7-21.7511124.1101.25Snow
861/4/2012 14:00-11.3-19.053719.3100.97Snow
871/4/2012 15:00-10.2-16.361119.7100.89Snow
881/4/2012 16:00-9.4-15.5611319.3100.79Snow
...........................
877912/31/2012 19:000.1-2.781309.7100.13Snow
878012/31/2012 20:000.2-2.483249.7100.03Snow
878112/31/2012 21:00-0.5-1.593284.899.95Snow
878212/31/2012 22:00-0.2-1.889289.799.91Snow
878312/31/2012 23:000.0-2.1863011.399.89Snow
\n", + "

390 rows × 8 columns

\n", + "
" + ], + "text/plain": [ + " Date/Time Temp_C Dew Point Temp_C Rel Hum_% Wind Speed_km/h \\\n", + "55 1/3/2012 7:00 -14.0 -19.5 63 19 \n", + "84 1/4/2012 12:00 -13.7 -21.7 51 11 \n", + "86 1/4/2012 14:00 -11.3 -19.0 53 7 \n", + "87 1/4/2012 15:00 -10.2 -16.3 61 11 \n", + "88 1/4/2012 16:00 -9.4 -15.5 61 13 \n", + "... ... ... ... ... ... \n", + "8779 12/31/2012 19:00 0.1 -2.7 81 30 \n", + "8780 12/31/2012 20:00 0.2 -2.4 83 24 \n", + "8781 12/31/2012 21:00 -0.5 -1.5 93 28 \n", + "8782 12/31/2012 22:00 -0.2 -1.8 89 28 \n", + "8783 12/31/2012 23:00 0.0 -2.1 86 30 \n", + "\n", + " Visibility_km Press_kPa Weather Condition \n", + "55 25.0 100.95 Snow \n", + "84 24.1 101.25 Snow \n", + "86 19.3 100.97 Snow \n", + "87 9.7 100.89 Snow \n", + "88 19.3 100.79 Snow \n", + "... ... ... ... \n", + "8779 9.7 100.13 Snow \n", + "8780 9.7 100.03 Snow \n", + "8781 4.8 99.95 Snow \n", + "8782 9.7 99.91 Snow \n", + "8783 11.3 99.89 Snow \n", + "\n", + "[390 rows x 8 columns]" + ] + }, + "execution_count": 57, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# groupby\n", + "data.groupby('Weather Condition').get_group('Snow')" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "id": "1fb0e430", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Date/TimeTemp_CDew Point Temp_CRel Hum_%Wind Speed_km/hVisibility_kmPress_kPaWeather Condition
868012/27/2012 16:00-4.5-6.288372.0100.44Snow,Blowing Snow
868112/27/2012 17:00-4.2-5.988323.2100.47Snow,Blowing Snow
868212/27/2012 18:00-4.0-5.788288.0100.49Snow,Blowing Snow
868312/27/2012 19:00-3.9-5.688269.7100.52Snow,Blowing Snow
868412/27/2012 20:00-3.7-5.3893716.1100.58Snow
868512/27/2012 21:00-3.7-4.892244.8100.62Freezing Drizzle,Snow
868612/27/2012 22:00-3.8-4.694204.8100.65Freezing Drizzle,Snow
868712/27/2012 23:00-4.0-5.689249.7100.70Snow
868812/28/2012 0:00-4.2-5.789198.0100.78Freezing Drizzle,Snow
868912/28/2012 1:00-4.4-6.685156.4100.83Freezing Drizzle,Snow
869012/28/2012 2:00-4.3-6.3861112.9100.93Freezing Drizzle,Snow
869112/28/2012 3:00-4.6-5.991134.0101.01Snow
869212/28/2012 4:00-4.9-5.99399.7101.00Snow
872312/29/2012 11:00-10.9-12.29076.4101.09Snow Showers,Fog
872412/29/2012 12:00-10.5-11.692118.0100.93Snow Showers,Fog
872512/29/2012 13:00-10.0-11.192229.7100.63Snow Showers,Fog
872612/29/2012 14:00-9.3-10.591224.8100.60Snow,Fog
872712/29/2012 15:00-8.8-10.091201.2100.55Snow,Fog
872812/29/2012 16:00-8.5-9.990241.2100.49Snow,Fog
872912/29/2012 17:00-9.0-10.490192.4100.46Snow,Fog
873012/29/2012 18:00-9.3-10.988266.4100.38Snow,Fog
873112/29/2012 19:00-9.5-11.287263.2100.33Snow,Fog
873212/29/2012 20:00-9.7-11.686249.7100.25Snow,Fog
873312/29/2012 21:00-9.8-11.885248.0100.24Snow,Fog
873412/29/2012 22:00-10.1-11.689152.4100.20Snow,Fog
873512/29/2012 23:00-10.0-12.085206.4100.19Snow,Fog
873612/30/2012 0:00-9.6-11.387133.2100.23Snow,Fog
873712/30/2012 1:00-9.4-10.59292.4100.22Snow,Fog
873812/30/2012 2:00-9.3-10.49294.0100.28Snow,Fog
873912/30/2012 3:00-9.1-10.490113.6100.30Snow,Fog
874012/30/2012 4:00-9.3-10.690139.7100.28Snow,Fog
874112/30/2012 5:00-9.1-10.490114.0100.32Snow,Fog
874212/30/2012 6:00-9.3-10.889178.0100.39Snow,Fog
876712/31/2012 7:00-9.3-11.385019.3101.19Snow Showers
876812/31/2012 8:00-8.6-10.38743.2101.14Snow Showers
876912/31/2012 9:00-8.1-9.68942.4101.09Snow
877012/31/2012 10:00-7.4-8.98946.4101.05Snow,Fog
877112/31/2012 11:00-6.7-7.99199.7100.93Snow
877212/31/2012 12:00-5.8-7.588412.9100.78Snow
877312/31/2012 13:00-4.6-6.686412.9100.63Snow
877412/31/2012 14:00-3.4-5.784611.3100.57Snow
877512/31/2012 15:00-2.3-4.68499.7100.47Snow
877612/31/2012 16:00-1.4-4.0821312.9100.40Snow
877712/31/2012 17:00-1.1-3.385199.7100.30Snow
877812/31/2012 18:00-1.3-3.188179.7100.19Snow
877912/31/2012 19:000.1-2.781309.7100.13Snow
878012/31/2012 20:000.2-2.483249.7100.03Snow
878112/31/2012 21:00-0.5-1.593284.899.95Snow
878212/31/2012 22:00-0.2-1.889289.799.91Snow
878312/31/2012 23:000.0-2.1863011.399.89Snow
\n", + "
" + ], + "text/plain": [ + " Date/Time Temp_C Dew Point Temp_C Rel Hum_% Wind Speed_km/h \\\n", + "8680 12/27/2012 16:00 -4.5 -6.2 88 37 \n", + "8681 12/27/2012 17:00 -4.2 -5.9 88 32 \n", + "8682 12/27/2012 18:00 -4.0 -5.7 88 28 \n", + "8683 12/27/2012 19:00 -3.9 -5.6 88 26 \n", + "8684 12/27/2012 20:00 -3.7 -5.3 89 37 \n", + "8685 12/27/2012 21:00 -3.7 -4.8 92 24 \n", + "8686 12/27/2012 22:00 -3.8 -4.6 94 20 \n", + "8687 12/27/2012 23:00 -4.0 -5.6 89 24 \n", + "8688 12/28/2012 0:00 -4.2 -5.7 89 19 \n", + "8689 12/28/2012 1:00 -4.4 -6.6 85 15 \n", + "8690 12/28/2012 2:00 -4.3 -6.3 86 11 \n", + "8691 12/28/2012 3:00 -4.6 -5.9 91 13 \n", + "8692 12/28/2012 4:00 -4.9 -5.9 93 9 \n", + "8723 12/29/2012 11:00 -10.9 -12.2 90 7 \n", + "8724 12/29/2012 12:00 -10.5 -11.6 92 11 \n", + "8725 12/29/2012 13:00 -10.0 -11.1 92 22 \n", + "8726 12/29/2012 14:00 -9.3 -10.5 91 22 \n", + "8727 12/29/2012 15:00 -8.8 -10.0 91 20 \n", + "8728 12/29/2012 16:00 -8.5 -9.9 90 24 \n", + "8729 12/29/2012 17:00 -9.0 -10.4 90 19 \n", + "8730 12/29/2012 18:00 -9.3 -10.9 88 26 \n", + "8731 12/29/2012 19:00 -9.5 -11.2 87 26 \n", + "8732 12/29/2012 20:00 -9.7 -11.6 86 24 \n", + "8733 12/29/2012 21:00 -9.8 -11.8 85 24 \n", + "8734 12/29/2012 22:00 -10.1 -11.6 89 15 \n", + "8735 12/29/2012 23:00 -10.0 -12.0 85 20 \n", + "8736 12/30/2012 0:00 -9.6 -11.3 87 13 \n", + "8737 12/30/2012 1:00 -9.4 -10.5 92 9 \n", + "8738 12/30/2012 2:00 -9.3 -10.4 92 9 \n", + "8739 12/30/2012 3:00 -9.1 -10.4 90 11 \n", + "8740 12/30/2012 4:00 -9.3 -10.6 90 13 \n", + "8741 12/30/2012 5:00 -9.1 -10.4 90 11 \n", + "8742 12/30/2012 6:00 -9.3 -10.8 89 17 \n", + "8767 12/31/2012 7:00 -9.3 -11.3 85 0 \n", + "8768 12/31/2012 8:00 -8.6 -10.3 87 4 \n", + "8769 12/31/2012 9:00 -8.1 -9.6 89 4 \n", + "8770 12/31/2012 10:00 -7.4 -8.9 89 4 \n", + "8771 12/31/2012 11:00 -6.7 -7.9 91 9 \n", + "8772 12/31/2012 12:00 -5.8 -7.5 88 4 \n", + "8773 12/31/2012 13:00 -4.6 -6.6 86 4 \n", + "8774 12/31/2012 14:00 -3.4 -5.7 84 6 \n", + "8775 12/31/2012 15:00 -2.3 -4.6 84 9 \n", + "8776 12/31/2012 16:00 -1.4 -4.0 82 13 \n", + "8777 12/31/2012 17:00 -1.1 -3.3 85 19 \n", + "8778 12/31/2012 18:00 -1.3 -3.1 88 17 \n", + "8779 12/31/2012 19:00 0.1 -2.7 81 30 \n", + "8780 12/31/2012 20:00 0.2 -2.4 83 24 \n", + "8781 12/31/2012 21:00 -0.5 -1.5 93 28 \n", + "8782 12/31/2012 22:00 -0.2 -1.8 89 28 \n", + "8783 12/31/2012 23:00 0.0 -2.1 86 30 \n", + "\n", + " Visibility_km Press_kPa Weather Condition \n", + "8680 2.0 100.44 Snow,Blowing Snow \n", + "8681 3.2 100.47 Snow,Blowing Snow \n", + "8682 8.0 100.49 Snow,Blowing Snow \n", + "8683 9.7 100.52 Snow,Blowing Snow \n", + "8684 16.1 100.58 Snow \n", + "8685 4.8 100.62 Freezing Drizzle,Snow \n", + "8686 4.8 100.65 Freezing Drizzle,Snow \n", + "8687 9.7 100.70 Snow \n", + "8688 8.0 100.78 Freezing Drizzle,Snow \n", + "8689 6.4 100.83 Freezing Drizzle,Snow \n", + "8690 12.9 100.93 Freezing Drizzle,Snow \n", + "8691 4.0 101.01 Snow \n", + "8692 9.7 101.00 Snow \n", + "8723 6.4 101.09 Snow Showers,Fog \n", + "8724 8.0 100.93 Snow Showers,Fog \n", + "8725 9.7 100.63 Snow Showers,Fog \n", + "8726 4.8 100.60 Snow,Fog \n", + "8727 1.2 100.55 Snow,Fog \n", + "8728 1.2 100.49 Snow,Fog \n", + "8729 2.4 100.46 Snow,Fog \n", + "8730 6.4 100.38 Snow,Fog \n", + "8731 3.2 100.33 Snow,Fog \n", + "8732 9.7 100.25 Snow,Fog \n", + "8733 8.0 100.24 Snow,Fog \n", + "8734 2.4 100.20 Snow,Fog \n", + "8735 6.4 100.19 Snow,Fog \n", + "8736 3.2 100.23 Snow,Fog \n", + "8737 2.4 100.22 Snow,Fog \n", + "8738 4.0 100.28 Snow,Fog \n", + "8739 3.6 100.30 Snow,Fog \n", + "8740 9.7 100.28 Snow,Fog \n", + "8741 4.0 100.32 Snow,Fog \n", + "8742 8.0 100.39 Snow,Fog \n", + "8767 19.3 101.19 Snow Showers \n", + "8768 3.2 101.14 Snow Showers \n", + "8769 2.4 101.09 Snow \n", + "8770 6.4 101.05 Snow,Fog \n", + "8771 9.7 100.93 Snow \n", + "8772 12.9 100.78 Snow \n", + "8773 12.9 100.63 Snow \n", + "8774 11.3 100.57 Snow \n", + "8775 9.7 100.47 Snow \n", + "8776 12.9 100.40 Snow \n", + "8777 9.7 100.30 Snow \n", + "8778 9.7 100.19 Snow \n", + "8779 9.7 100.13 Snow \n", + "8780 9.7 100.03 Snow \n", + "8781 4.8 99.95 Snow \n", + "8782 9.7 99.91 Snow \n", + "8783 11.3 99.89 Snow " + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# str.contains\n", + "data[data['Weather Condition'].str.contains('Snow')].tail(50)" + ] + }, + { + "cell_type": "markdown", + "id": "a78034c1", + "metadata": {}, + "source": [ + "## Q) 10. Find all instances when 'Wind Speed is above 24' and 'Visibility is 25'." + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "id": "68f6795c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Date/TimeTemp_CDew Point Temp_CRel Hum_%Wind Speed_km/hVisibility_kmPress_kPaWeather Condition
231/1/2012 23:005.32.0793025.099.31Cloudy
241/2/2012 0:005.21.5773525.099.26Rain Showers
251/2/2012 1:004.60.0723925.099.26Cloudy
261/2/2012 2:003.9-0.9713225.099.26Mostly Cloudy
271/2/2012 3:003.7-1.5693325.099.30Mostly Cloudy
...........................
870512/28/2012 17:00-8.6-12.0762625.0101.34Mainly Clear
875312/30/2012 17:00-12.1-15.8742825.0101.26Mainly Clear
875512/30/2012 19:00-13.4-16.5772625.0101.47Mainly Clear
875912/30/2012 23:00-12.1-15.1782825.0101.52Mostly Cloudy
876012/31/2012 0:00-11.1-14.4772625.0101.51Cloudy
\n", + "

308 rows × 8 columns

\n", + "
" + ], + "text/plain": [ + " Date/Time Temp_C Dew Point Temp_C Rel Hum_% Wind Speed_km/h \\\n", + "23 1/1/2012 23:00 5.3 2.0 79 30 \n", + "24 1/2/2012 0:00 5.2 1.5 77 35 \n", + "25 1/2/2012 1:00 4.6 0.0 72 39 \n", + "26 1/2/2012 2:00 3.9 -0.9 71 32 \n", + "27 1/2/2012 3:00 3.7 -1.5 69 33 \n", + "... ... ... ... ... ... \n", + "8705 12/28/2012 17:00 -8.6 -12.0 76 26 \n", + "8753 12/30/2012 17:00 -12.1 -15.8 74 28 \n", + "8755 12/30/2012 19:00 -13.4 -16.5 77 26 \n", + "8759 12/30/2012 23:00 -12.1 -15.1 78 28 \n", + "8760 12/31/2012 0:00 -11.1 -14.4 77 26 \n", + "\n", + " Visibility_km Press_kPa Weather Condition \n", + "23 25.0 99.31 Cloudy \n", + "24 25.0 99.26 Rain Showers \n", + "25 25.0 99.26 Cloudy \n", + "26 25.0 99.26 Mostly Cloudy \n", + "27 25.0 99.30 Mostly Cloudy \n", + "... ... ... ... \n", + "8705 25.0 101.34 Mainly Clear \n", + "8753 25.0 101.26 Mainly Clear \n", + "8755 25.0 101.47 Mainly Clear \n", + "8759 25.0 101.52 Mostly Cloudy \n", + "8760 25.0 101.51 Cloudy \n", + "\n", + "[308 rows x 8 columns]" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data[(data['Wind Speed_km/h'] > 24) & (data['Visibility_km'] == 25)]" + ] + }, + { + "cell_type": "markdown", + "id": "c80f196b", + "metadata": {}, + "source": [ + "## Q) 11. What is the Mean value of each column against each 'Weather Condition'?" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "id": "5e91ce1c", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\anand\\AppData\\Local\\Temp\\ipykernel_85796\\17017135.py:1: FutureWarning: The default value of numeric_only in DataFrameGroupBy.mean is deprecated. In a future version, numeric_only will default to False. Either specify numeric_only or select only columns which should be valid for the function.\n", + " data.groupby('Weather Condition').mean()\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Temp_CDew Point Temp_CRel Hum_%Wind Speed_km/hVisibility_kmPress_kPa
Weather Condition
Clear6.8257160.08936764.49773810.55731530.153243101.587443
Cloudy7.9705442.37581069.59259316.12731526.625752100.911441
Drizzle7.3536595.50487888.24390216.09756117.931707100.435366
Drizzle,Fog8.0675007.03375093.27500011.8625005.257500100.786625
Drizzle,Ice Pellets,Fog0.400000-0.70000092.00000020.0000004.000000100.790000
Drizzle,Snow1.0500000.15000093.50000014.00000010.500000100.890000
Drizzle,Snow,Fog0.6933330.12000095.86666715.5333335.51333399.281333
Fog4.3033333.15933392.2866677.9466676.248000101.184067
Freezing Drizzle-5.657143-8.00000083.57142916.5714299.200000100.202857
Freezing Drizzle,Fog-2.533333-4.18333388.50000017.0000005.266667100.441667
Freezing Drizzle,Haze-5.433333-8.00000082.00000010.3333332.666667100.316667
Freezing Drizzle,Snow-5.109091-7.07272786.09090916.2727275.872727100.520909
Freezing Fog-7.575000-9.25000087.7500004.7500000.650000102.320000
Freezing Rain-3.885714-6.07857184.64285719.2142868.24285799.647143
Freezing Rain,Fog-2.225000-3.75000089.50000015.5000007.55000099.945000
Freezing Rain,Haze-4.900000-7.45000082.5000007.5000002.400000100.375000
Freezing Rain,Ice Pellets,Fog-2.600000-3.70000092.00000028.0000008.000000100.950000
Freezing Rain,Snow Grains-5.000000-7.30000084.00000032.0000004.80000098.560000
Haze-0.200000-2.97500081.62500010.4375007.831250101.482500
Mainly Clear12.5589274.58167160.66714214.14482434.264862101.248832
Moderate Rain,Fog1.7000000.80000094.00000017.0000006.40000099.980000
Moderate Snow-5.525000-7.25000087.75000033.7500000.750000100.275000
Moderate Snow,Blowing Snow-5.450000-6.50000092.50000040.0000000.600000100.570000
Mostly Cloudy10.5742873.13117462.10246515.81392031.253842101.025288
Rain9.7862757.04281083.62418319.25490218.856536100.233333
Rain Showers13.7223409.18776675.15957417.13297922.816489100.404043
Rain Showers,Fog12.80000012.10000096.00000013.0000006.40000099.830000
Rain Showers,Snow Showers2.150000-1.50000076.50000022.50000021.700000101.100000
Rain,Fog8.2732767.21982893.18965514.7931036.873276100.500862
Rain,Haze4.6333332.06666783.33333311.6666676.700000100.540000
Rain,Ice Pellets0.600000-0.60000092.00000024.0000009.700000100.120000
Rain,Snow1.055556-0.56666789.00000028.38888911.67222299.951111
Rain,Snow Grains1.900000-2.10000075.00000026.00000025.000000100.600000
Rain,Snow,Fog0.8000000.30000096.0000009.0000006.400000100.730000
Rain,Snow,Ice Pellets1.100000-0.17500091.50000023.2500006.000000100.105000
Snow-4.524103-7.62333379.30769220.03846211.171795100.536103
Snow Pellets0.700000-6.40000059.00000035.0000002.40000099.700000
Snow Showers-3.506667-7.86666772.35000019.23333320.158333100.963500
Snow Showers,Fog-10.675000-11.90000090.75000013.7500007.025000101.292500
Snow,Blowing Snow-5.410526-7.62105384.47368434.8421054.10526399.704737
Snow,Fog-5.075676-6.36486590.67567617.3243244.537838100.688649
Snow,Haze-4.020000-6.86000080.6000005.0000004.640000100.782000
Snow,Ice Pellets-1.883333-3.66666787.66666723.8333337.416667100.548333
Thunderstorms24.15000019.75000077.0000007.50000024.550000100.230000
Thunderstorms,Heavy Rain Showers10.9000009.00000088.0000009.0000002.400000100.260000
Thunderstorms,Moderate Rain Showers,Fog19.60000018.50000093.00000015.0000003.200000100.010000
Thunderstorms,Rain20.43333318.53333389.00000015.66666719.833333100.420000
Thunderstorms,Rain Showers20.03750017.61875086.37500018.31250015.893750100.233750
Thunderstorms,Rain Showers,Fog21.60000018.70000084.00000019.6666679.700000100.063333
Thunderstorms,Rain,Fog20.60000018.60000088.00000019.0000004.800000100.080000
\n", + "
" + ], + "text/plain": [ + " Temp_C Dew Point Temp_C \\\n", + "Weather Condition \n", + "Clear 6.825716 0.089367 \n", + "Cloudy 7.970544 2.375810 \n", + "Drizzle 7.353659 5.504878 \n", + "Drizzle,Fog 8.067500 7.033750 \n", + "Drizzle,Ice Pellets,Fog 0.400000 -0.700000 \n", + "Drizzle,Snow 1.050000 0.150000 \n", + "Drizzle,Snow,Fog 0.693333 0.120000 \n", + "Fog 4.303333 3.159333 \n", + "Freezing Drizzle -5.657143 -8.000000 \n", + "Freezing Drizzle,Fog -2.533333 -4.183333 \n", + "Freezing Drizzle,Haze -5.433333 -8.000000 \n", + "Freezing Drizzle,Snow -5.109091 -7.072727 \n", + "Freezing Fog -7.575000 -9.250000 \n", + "Freezing Rain -3.885714 -6.078571 \n", + "Freezing Rain,Fog -2.225000 -3.750000 \n", + "Freezing Rain,Haze -4.900000 -7.450000 \n", + "Freezing Rain,Ice Pellets,Fog -2.600000 -3.700000 \n", + "Freezing Rain,Snow Grains -5.000000 -7.300000 \n", + "Haze -0.200000 -2.975000 \n", + "Mainly Clear 12.558927 4.581671 \n", + "Moderate Rain,Fog 1.700000 0.800000 \n", + "Moderate Snow -5.525000 -7.250000 \n", + "Moderate Snow,Blowing Snow -5.450000 -6.500000 \n", + "Mostly Cloudy 10.574287 3.131174 \n", + "Rain 9.786275 7.042810 \n", + "Rain Showers 13.722340 9.187766 \n", + "Rain Showers,Fog 12.800000 12.100000 \n", + "Rain Showers,Snow Showers 2.150000 -1.500000 \n", + "Rain,Fog 8.273276 7.219828 \n", + "Rain,Haze 4.633333 2.066667 \n", + "Rain,Ice Pellets 0.600000 -0.600000 \n", + "Rain,Snow 1.055556 -0.566667 \n", + "Rain,Snow Grains 1.900000 -2.100000 \n", + "Rain,Snow,Fog 0.800000 0.300000 \n", + "Rain,Snow,Ice Pellets 1.100000 -0.175000 \n", + "Snow -4.524103 -7.623333 \n", + "Snow Pellets 0.700000 -6.400000 \n", + "Snow Showers -3.506667 -7.866667 \n", + "Snow Showers,Fog -10.675000 -11.900000 \n", + "Snow,Blowing Snow -5.410526 -7.621053 \n", + "Snow,Fog -5.075676 -6.364865 \n", + "Snow,Haze -4.020000 -6.860000 \n", + "Snow,Ice Pellets -1.883333 -3.666667 \n", + "Thunderstorms 24.150000 19.750000 \n", + "Thunderstorms,Heavy Rain Showers 10.900000 9.000000 \n", + "Thunderstorms,Moderate Rain Showers,Fog 19.600000 18.500000 \n", + "Thunderstorms,Rain 20.433333 18.533333 \n", + "Thunderstorms,Rain Showers 20.037500 17.618750 \n", + "Thunderstorms,Rain Showers,Fog 21.600000 18.700000 \n", + "Thunderstorms,Rain,Fog 20.600000 18.600000 \n", + "\n", + " Rel Hum_% Wind Speed_km/h \\\n", + "Weather Condition \n", + "Clear 64.497738 10.557315 \n", + "Cloudy 69.592593 16.127315 \n", + "Drizzle 88.243902 16.097561 \n", + "Drizzle,Fog 93.275000 11.862500 \n", + "Drizzle,Ice Pellets,Fog 92.000000 20.000000 \n", + "Drizzle,Snow 93.500000 14.000000 \n", + "Drizzle,Snow,Fog 95.866667 15.533333 \n", + "Fog 92.286667 7.946667 \n", + "Freezing Drizzle 83.571429 16.571429 \n", + "Freezing Drizzle,Fog 88.500000 17.000000 \n", + "Freezing Drizzle,Haze 82.000000 10.333333 \n", + "Freezing Drizzle,Snow 86.090909 16.272727 \n", + "Freezing Fog 87.750000 4.750000 \n", + "Freezing Rain 84.642857 19.214286 \n", + "Freezing Rain,Fog 89.500000 15.500000 \n", + "Freezing Rain,Haze 82.500000 7.500000 \n", + "Freezing Rain,Ice Pellets,Fog 92.000000 28.000000 \n", + "Freezing Rain,Snow Grains 84.000000 32.000000 \n", + "Haze 81.625000 10.437500 \n", + "Mainly Clear 60.667142 14.144824 \n", + "Moderate Rain,Fog 94.000000 17.000000 \n", + "Moderate Snow 87.750000 33.750000 \n", + "Moderate Snow,Blowing Snow 92.500000 40.000000 \n", + "Mostly Cloudy 62.102465 15.813920 \n", + "Rain 83.624183 19.254902 \n", + "Rain Showers 75.159574 17.132979 \n", + "Rain Showers,Fog 96.000000 13.000000 \n", + "Rain Showers,Snow Showers 76.500000 22.500000 \n", + "Rain,Fog 93.189655 14.793103 \n", + "Rain,Haze 83.333333 11.666667 \n", + "Rain,Ice Pellets 92.000000 24.000000 \n", + "Rain,Snow 89.000000 28.388889 \n", + "Rain,Snow Grains 75.000000 26.000000 \n", + "Rain,Snow,Fog 96.000000 9.000000 \n", + "Rain,Snow,Ice Pellets 91.500000 23.250000 \n", + "Snow 79.307692 20.038462 \n", + "Snow Pellets 59.000000 35.000000 \n", + "Snow Showers 72.350000 19.233333 \n", + "Snow Showers,Fog 90.750000 13.750000 \n", + "Snow,Blowing Snow 84.473684 34.842105 \n", + "Snow,Fog 90.675676 17.324324 \n", + "Snow,Haze 80.600000 5.000000 \n", + "Snow,Ice Pellets 87.666667 23.833333 \n", + "Thunderstorms 77.000000 7.500000 \n", + "Thunderstorms,Heavy Rain Showers 88.000000 9.000000 \n", + "Thunderstorms,Moderate Rain Showers,Fog 93.000000 15.000000 \n", + "Thunderstorms,Rain 89.000000 15.666667 \n", + "Thunderstorms,Rain Showers 86.375000 18.312500 \n", + "Thunderstorms,Rain Showers,Fog 84.000000 19.666667 \n", + "Thunderstorms,Rain,Fog 88.000000 19.000000 \n", + "\n", + " Visibility_km Press_kPa \n", + "Weather Condition \n", + "Clear 30.153243 101.587443 \n", + "Cloudy 26.625752 100.911441 \n", + "Drizzle 17.931707 100.435366 \n", + "Drizzle,Fog 5.257500 100.786625 \n", + "Drizzle,Ice Pellets,Fog 4.000000 100.790000 \n", + "Drizzle,Snow 10.500000 100.890000 \n", + "Drizzle,Snow,Fog 5.513333 99.281333 \n", + "Fog 6.248000 101.184067 \n", + "Freezing Drizzle 9.200000 100.202857 \n", + "Freezing Drizzle,Fog 5.266667 100.441667 \n", + "Freezing Drizzle,Haze 2.666667 100.316667 \n", + "Freezing Drizzle,Snow 5.872727 100.520909 \n", + "Freezing Fog 0.650000 102.320000 \n", + "Freezing Rain 8.242857 99.647143 \n", + "Freezing Rain,Fog 7.550000 99.945000 \n", + "Freezing Rain,Haze 2.400000 100.375000 \n", + "Freezing Rain,Ice Pellets,Fog 8.000000 100.950000 \n", + "Freezing Rain,Snow Grains 4.800000 98.560000 \n", + "Haze 7.831250 101.482500 \n", + "Mainly Clear 34.264862 101.248832 \n", + "Moderate Rain,Fog 6.400000 99.980000 \n", + "Moderate Snow 0.750000 100.275000 \n", + "Moderate Snow,Blowing Snow 0.600000 100.570000 \n", + "Mostly Cloudy 31.253842 101.025288 \n", + "Rain 18.856536 100.233333 \n", + "Rain Showers 22.816489 100.404043 \n", + "Rain Showers,Fog 6.400000 99.830000 \n", + "Rain Showers,Snow Showers 21.700000 101.100000 \n", + "Rain,Fog 6.873276 100.500862 \n", + "Rain,Haze 6.700000 100.540000 \n", + "Rain,Ice Pellets 9.700000 100.120000 \n", + "Rain,Snow 11.672222 99.951111 \n", + "Rain,Snow Grains 25.000000 100.600000 \n", + "Rain,Snow,Fog 6.400000 100.730000 \n", + "Rain,Snow,Ice Pellets 6.000000 100.105000 \n", + "Snow 11.171795 100.536103 \n", + "Snow Pellets 2.400000 99.700000 \n", + "Snow Showers 20.158333 100.963500 \n", + "Snow Showers,Fog 7.025000 101.292500 \n", + "Snow,Blowing Snow 4.105263 99.704737 \n", + "Snow,Fog 4.537838 100.688649 \n", + "Snow,Haze 4.640000 100.782000 \n", + "Snow,Ice Pellets 7.416667 100.548333 \n", + "Thunderstorms 24.550000 100.230000 \n", + "Thunderstorms,Heavy Rain Showers 2.400000 100.260000 \n", + "Thunderstorms,Moderate Rain Showers,Fog 3.200000 100.010000 \n", + "Thunderstorms,Rain 19.833333 100.420000 \n", + "Thunderstorms,Rain Showers 15.893750 100.233750 \n", + "Thunderstorms,Rain Showers,Fog 9.700000 100.063333 \n", + "Thunderstorms,Rain,Fog 4.800000 100.080000 " + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.groupby('Weather Condition').mean()" + ] + }, + { + "cell_type": "markdown", + "id": "4444e02b", + "metadata": {}, + "source": [ + "## Q) 12. What is the Minimum & Maximum value of each column against each 'Weather Condition'?" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "id": "7d15d51d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Date/TimeTemp_CDew Point Temp_CRel Hum_%Wind Speed_km/hVisibility_kmPress_kPa
Weather Condition
Clear1/11/2012 1:00-23.3-28.520011.399.52
Cloudy1/1/2012 17:00-21.4-26.818011.398.39
Drizzle1/23/2012 21:001.1-0.27406.497.84
Drizzle,Fog1/23/2012 20:000.0-1.68501.098.65
Drizzle,Ice Pellets,Fog12/17/2012 9:000.4-0.792204.0100.79
Drizzle,Snow12/17/2012 15:000.90.19299.7100.63
Drizzle,Snow,Fog12/18/2012 21:000.3-0.19272.497.79
Fog1/1/2012 0:00-16.0-17.28000.298.31
Freezing Drizzle1/13/2012 10:00-9.0-12.27864.898.44
Freezing Drizzle,Fog1/1/2012 2:00-6.4-9.08263.698.74
Freezing Drizzle,Haze2/1/2012 11:00-5.8-8.38192.0100.28
Freezing Drizzle,Snow1/13/2012 3:00-8.3-10.47962.499.19
Freezing Fog1/22/2012 6:00-19.0-22.97100.2101.97
Freezing Rain1/13/2012 11:00-6.5-9.08172.898.22
Freezing Rain,Fog1/17/2012 23:00-6.1-8.78272.898.32
Freezing Rain,Haze2/1/2012 14:00-4.9-7.58262.0100.34
Freezing Rain,Ice Pellets,Fog12/17/2012 3:00-2.6-3.792288.0100.95
Freezing Rain,Snow Grains1/13/2012 9:00-5.0-7.384324.898.56
Haze1/22/2012 12:00-11.5-16.06804.8100.35
Mainly Clear1/10/2012 11:00-22.8-28.020012.998.67
Moderate Rain,Fog12/10/2012 8:001.70.894176.499.98
Moderate Snow1/12/2012 15:00-6.3-7.683260.699.88
Moderate Snow,Blowing Snow12/27/2012 10:00-5.5-6.692390.6100.50
Mostly Cloudy1/1/2012 16:00-23.2-28.518011.398.36
Rain1/1/2012 18:000.3-5.74004.097.52
Rain Showers1/1/2012 22:001.6-7.23706.498.51
Rain Showers,Fog10/20/2012 3:0012.812.196136.499.83
Rain Showers,Snow Showers11/4/2012 8:002.1-1.8751719.3101.09
Rain,Fog1/23/2012 18:000.0-1.28302.098.61
Rain,Haze3/13/2012 7:004.01.08174.0100.50
Rain,Ice Pellets12/18/2012 5:000.6-0.692249.7100.12
Rain,Snow1/10/2012 5:000.6-1.781132.498.18
Rain,Snow Grains12/21/2012 0:001.9-2.1752625.0100.60
Rain,Snow,Fog12/8/2012 21:000.80.39696.4100.73
Rain,Snow,Ice Pellets12/21/2012 1:000.9-0.788174.899.85
Snow1/10/2012 1:00-16.7-24.64101.097.75
Snow Pellets11/24/2012 15:000.7-6.459352.499.70
Snow Showers1/12/2012 7:00-13.3-19.35202.499.49
Snow Showers,Fog12/26/2012 9:00-11.3-12.78974.0100.63
Snow,Blowing Snow1/13/2012 21:00-12.0-16.270240.698.11
Snow,Fog12/16/2012 15:00-10.1-12.07741.299.38
Snow,Haze2/1/2012 17:00-4.3-7.28004.0100.61
Snow,Ice Pellets12/10/2012 3:00-4.3-5.976192.899.40
Thunderstorms7/16/2012 1:0021.619.467024.199.84
Thunderstorms,Heavy Rain Showers5/29/2012 6:0010.99.08892.4100.26
Thunderstorms,Moderate Rain Showers,Fog7/17/2012 6:0019.618.593153.2100.01
Thunderstorms,Rain5/25/2012 20:0019.418.283416.1100.19
Thunderstorms,Rain Showers5/29/2012 16:0011.07.06876.499.65
Thunderstorms,Rain Showers,Fog6/29/2012 3:0019.516.18079.799.71
Thunderstorms,Rain,Fog7/17/2012 5:0020.618.688194.8100.08
\n", + "
" + ], + "text/plain": [ + " Date/Time Temp_C \\\n", + "Weather Condition \n", + "Clear 1/11/2012 1:00 -23.3 \n", + "Cloudy 1/1/2012 17:00 -21.4 \n", + "Drizzle 1/23/2012 21:00 1.1 \n", + "Drizzle,Fog 1/23/2012 20:00 0.0 \n", + "Drizzle,Ice Pellets,Fog 12/17/2012 9:00 0.4 \n", + "Drizzle,Snow 12/17/2012 15:00 0.9 \n", + "Drizzle,Snow,Fog 12/18/2012 21:00 0.3 \n", + "Fog 1/1/2012 0:00 -16.0 \n", + "Freezing Drizzle 1/13/2012 10:00 -9.0 \n", + "Freezing Drizzle,Fog 1/1/2012 2:00 -6.4 \n", + "Freezing Drizzle,Haze 2/1/2012 11:00 -5.8 \n", + "Freezing Drizzle,Snow 1/13/2012 3:00 -8.3 \n", + "Freezing Fog 1/22/2012 6:00 -19.0 \n", + "Freezing Rain 1/13/2012 11:00 -6.5 \n", + "Freezing Rain,Fog 1/17/2012 23:00 -6.1 \n", + "Freezing Rain,Haze 2/1/2012 14:00 -4.9 \n", + "Freezing Rain,Ice Pellets,Fog 12/17/2012 3:00 -2.6 \n", + "Freezing Rain,Snow Grains 1/13/2012 9:00 -5.0 \n", + "Haze 1/22/2012 12:00 -11.5 \n", + "Mainly Clear 1/10/2012 11:00 -22.8 \n", + "Moderate Rain,Fog 12/10/2012 8:00 1.7 \n", + "Moderate Snow 1/12/2012 15:00 -6.3 \n", + "Moderate Snow,Blowing Snow 12/27/2012 10:00 -5.5 \n", + "Mostly Cloudy 1/1/2012 16:00 -23.2 \n", + "Rain 1/1/2012 18:00 0.3 \n", + "Rain Showers 1/1/2012 22:00 1.6 \n", + "Rain Showers,Fog 10/20/2012 3:00 12.8 \n", + "Rain Showers,Snow Showers 11/4/2012 8:00 2.1 \n", + "Rain,Fog 1/23/2012 18:00 0.0 \n", + "Rain,Haze 3/13/2012 7:00 4.0 \n", + "Rain,Ice Pellets 12/18/2012 5:00 0.6 \n", + "Rain,Snow 1/10/2012 5:00 0.6 \n", + "Rain,Snow Grains 12/21/2012 0:00 1.9 \n", + "Rain,Snow,Fog 12/8/2012 21:00 0.8 \n", + "Rain,Snow,Ice Pellets 12/21/2012 1:00 0.9 \n", + "Snow 1/10/2012 1:00 -16.7 \n", + "Snow Pellets 11/24/2012 15:00 0.7 \n", + "Snow Showers 1/12/2012 7:00 -13.3 \n", + "Snow Showers,Fog 12/26/2012 9:00 -11.3 \n", + "Snow,Blowing Snow 1/13/2012 21:00 -12.0 \n", + "Snow,Fog 12/16/2012 15:00 -10.1 \n", + "Snow,Haze 2/1/2012 17:00 -4.3 \n", + "Snow,Ice Pellets 12/10/2012 3:00 -4.3 \n", + "Thunderstorms 7/16/2012 1:00 21.6 \n", + "Thunderstorms,Heavy Rain Showers 5/29/2012 6:00 10.9 \n", + "Thunderstorms,Moderate Rain Showers,Fog 7/17/2012 6:00 19.6 \n", + "Thunderstorms,Rain 5/25/2012 20:00 19.4 \n", + "Thunderstorms,Rain Showers 5/29/2012 16:00 11.0 \n", + "Thunderstorms,Rain Showers,Fog 6/29/2012 3:00 19.5 \n", + "Thunderstorms,Rain,Fog 7/17/2012 5:00 20.6 \n", + "\n", + " Dew Point Temp_C Rel Hum_% \\\n", + "Weather Condition \n", + "Clear -28.5 20 \n", + "Cloudy -26.8 18 \n", + "Drizzle -0.2 74 \n", + "Drizzle,Fog -1.6 85 \n", + "Drizzle,Ice Pellets,Fog -0.7 92 \n", + "Drizzle,Snow 0.1 92 \n", + "Drizzle,Snow,Fog -0.1 92 \n", + "Fog -17.2 80 \n", + "Freezing Drizzle -12.2 78 \n", + "Freezing Drizzle,Fog -9.0 82 \n", + "Freezing Drizzle,Haze -8.3 81 \n", + "Freezing Drizzle,Snow -10.4 79 \n", + "Freezing Fog -22.9 71 \n", + "Freezing Rain -9.0 81 \n", + "Freezing Rain,Fog -8.7 82 \n", + "Freezing Rain,Haze -7.5 82 \n", + "Freezing Rain,Ice Pellets,Fog -3.7 92 \n", + "Freezing Rain,Snow Grains -7.3 84 \n", + "Haze -16.0 68 \n", + "Mainly Clear -28.0 20 \n", + "Moderate Rain,Fog 0.8 94 \n", + "Moderate Snow -7.6 83 \n", + "Moderate Snow,Blowing Snow -6.6 92 \n", + "Mostly Cloudy -28.5 18 \n", + "Rain -5.7 40 \n", + "Rain Showers -7.2 37 \n", + "Rain Showers,Fog 12.1 96 \n", + "Rain Showers,Snow Showers -1.8 75 \n", + "Rain,Fog -1.2 83 \n", + "Rain,Haze 1.0 81 \n", + "Rain,Ice Pellets -0.6 92 \n", + "Rain,Snow -1.7 81 \n", + "Rain,Snow Grains -2.1 75 \n", + "Rain,Snow,Fog 0.3 96 \n", + "Rain,Snow,Ice Pellets -0.7 88 \n", + "Snow -24.6 41 \n", + "Snow Pellets -6.4 59 \n", + "Snow Showers -19.3 52 \n", + "Snow Showers,Fog -12.7 89 \n", + "Snow,Blowing Snow -16.2 70 \n", + "Snow,Fog -12.0 77 \n", + "Snow,Haze -7.2 80 \n", + "Snow,Ice Pellets -5.9 76 \n", + "Thunderstorms 19.4 67 \n", + "Thunderstorms,Heavy Rain Showers 9.0 88 \n", + "Thunderstorms,Moderate Rain Showers,Fog 18.5 93 \n", + "Thunderstorms,Rain 18.2 83 \n", + "Thunderstorms,Rain Showers 7.0 68 \n", + "Thunderstorms,Rain Showers,Fog 16.1 80 \n", + "Thunderstorms,Rain,Fog 18.6 88 \n", + "\n", + " Wind Speed_km/h Visibility_km \\\n", + "Weather Condition \n", + "Clear 0 11.3 \n", + "Cloudy 0 11.3 \n", + "Drizzle 0 6.4 \n", + "Drizzle,Fog 0 1.0 \n", + "Drizzle,Ice Pellets,Fog 20 4.0 \n", + "Drizzle,Snow 9 9.7 \n", + "Drizzle,Snow,Fog 7 2.4 \n", + "Fog 0 0.2 \n", + "Freezing Drizzle 6 4.8 \n", + "Freezing Drizzle,Fog 6 3.6 \n", + "Freezing Drizzle,Haze 9 2.0 \n", + "Freezing Drizzle,Snow 6 2.4 \n", + "Freezing Fog 0 0.2 \n", + "Freezing Rain 7 2.8 \n", + "Freezing Rain,Fog 7 2.8 \n", + "Freezing Rain,Haze 6 2.0 \n", + "Freezing Rain,Ice Pellets,Fog 28 8.0 \n", + "Freezing Rain,Snow Grains 32 4.8 \n", + "Haze 0 4.8 \n", + "Mainly Clear 0 12.9 \n", + "Moderate Rain,Fog 17 6.4 \n", + "Moderate Snow 26 0.6 \n", + "Moderate Snow,Blowing Snow 39 0.6 \n", + "Mostly Cloudy 0 11.3 \n", + "Rain 0 4.0 \n", + "Rain Showers 0 6.4 \n", + "Rain Showers,Fog 13 6.4 \n", + "Rain Showers,Snow Showers 17 19.3 \n", + "Rain,Fog 0 2.0 \n", + "Rain,Haze 7 4.0 \n", + "Rain,Ice Pellets 24 9.7 \n", + "Rain,Snow 13 2.4 \n", + "Rain,Snow Grains 26 25.0 \n", + "Rain,Snow,Fog 9 6.4 \n", + "Rain,Snow,Ice Pellets 17 4.8 \n", + "Snow 0 1.0 \n", + "Snow Pellets 35 2.4 \n", + "Snow Showers 0 2.4 \n", + "Snow Showers,Fog 7 4.0 \n", + "Snow,Blowing Snow 24 0.6 \n", + "Snow,Fog 4 1.2 \n", + "Snow,Haze 0 4.0 \n", + "Snow,Ice Pellets 19 2.8 \n", + "Thunderstorms 0 24.1 \n", + "Thunderstorms,Heavy Rain Showers 9 2.4 \n", + "Thunderstorms,Moderate Rain Showers,Fog 15 3.2 \n", + "Thunderstorms,Rain 4 16.1 \n", + "Thunderstorms,Rain Showers 7 6.4 \n", + "Thunderstorms,Rain Showers,Fog 7 9.7 \n", + "Thunderstorms,Rain,Fog 19 4.8 \n", + "\n", + " Press_kPa \n", + "Weather Condition \n", + "Clear 99.52 \n", + "Cloudy 98.39 \n", + "Drizzle 97.84 \n", + "Drizzle,Fog 98.65 \n", + "Drizzle,Ice Pellets,Fog 100.79 \n", + "Drizzle,Snow 100.63 \n", + "Drizzle,Snow,Fog 97.79 \n", + "Fog 98.31 \n", + "Freezing Drizzle 98.44 \n", + "Freezing Drizzle,Fog 98.74 \n", + "Freezing Drizzle,Haze 100.28 \n", + "Freezing Drizzle,Snow 99.19 \n", + "Freezing Fog 101.97 \n", + "Freezing Rain 98.22 \n", + "Freezing Rain,Fog 98.32 \n", + "Freezing Rain,Haze 100.34 \n", + "Freezing Rain,Ice Pellets,Fog 100.95 \n", + "Freezing Rain,Snow Grains 98.56 \n", + "Haze 100.35 \n", + "Mainly Clear 98.67 \n", + "Moderate Rain,Fog 99.98 \n", + "Moderate Snow 99.88 \n", + "Moderate Snow,Blowing Snow 100.50 \n", + "Mostly Cloudy 98.36 \n", + "Rain 97.52 \n", + "Rain Showers 98.51 \n", + "Rain Showers,Fog 99.83 \n", + "Rain Showers,Snow Showers 101.09 \n", + "Rain,Fog 98.61 \n", + "Rain,Haze 100.50 \n", + "Rain,Ice Pellets 100.12 \n", + "Rain,Snow 98.18 \n", + "Rain,Snow Grains 100.60 \n", + "Rain,Snow,Fog 100.73 \n", + "Rain,Snow,Ice Pellets 99.85 \n", + "Snow 97.75 \n", + "Snow Pellets 99.70 \n", + "Snow Showers 99.49 \n", + "Snow Showers,Fog 100.63 \n", + "Snow,Blowing Snow 98.11 \n", + "Snow,Fog 99.38 \n", + "Snow,Haze 100.61 \n", + "Snow,Ice Pellets 99.40 \n", + "Thunderstorms 99.84 \n", + "Thunderstorms,Heavy Rain Showers 100.26 \n", + "Thunderstorms,Moderate Rain Showers,Fog 100.01 \n", + "Thunderstorms,Rain 100.19 \n", + "Thunderstorms,Rain Showers 99.65 \n", + "Thunderstorms,Rain Showers,Fog 99.71 \n", + "Thunderstorms,Rain,Fog 100.08 " + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.groupby('Weather Condition').min()" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "id": "76244dd4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Date/TimeTemp_CDew Point Temp_CRel Hum_%Wind Speed_km/hVisibility_kmPress_kPa
Weather Condition
Clear9/9/2012 5:0032.820.4993348.3103.63
Cloudy9/9/2012 23:0030.522.6995448.3103.65
Drizzle9/30/2012 3:0018.817.7963025.0101.56
Drizzle,Fog9/30/2012 2:0019.919.1100289.7102.07
Drizzle,Ice Pellets,Fog12/17/2012 9:000.4-0.792204.0100.79
Drizzle,Snow12/19/2012 18:001.20.2951911.3101.15
Drizzle,Snow,Fog12/22/2012 3:001.10.698329.7100.15
Fog9/22/2012 0:0020.819.6100229.7103.04
Freezing Drizzle2/1/2012 5:00-2.3-3.3932612.9101.02
Freezing Drizzle,Fog12/10/2012 5:00-0.3-2.394338.0101.27
Freezing Drizzle,Haze2/1/2012 13:00-5.0-7.783114.0100.36
Freezing Drizzle,Snow3/2/2012 12:00-3.3-4.6942412.9101.18
Freezing Fog3/17/2012 6:00-0.1-0.39990.8102.85
Freezing Rain2/1/2012 7:000.3-1.7922816.1101.00
Freezing Rain,Fog12/17/2012 1:000.1-0.993269.7101.01
Freezing Rain,Haze2/1/2012 15:00-4.9-7.48392.8100.41
Freezing Rain,Ice Pellets,Fog12/17/2012 3:00-2.6-3.792288.0100.95
Freezing Rain,Snow Grains1/13/2012 9:00-5.0-7.384324.898.56
Haze3/13/2012 23:0014.111.186179.7102.97
Mainly Clear9/9/2012 9:0033.021.2996348.3103.59
Moderate Rain,Fog12/10/2012 8:001.70.894176.499.98
Moderate Snow12/27/2012 9:00-4.9-6.793390.8100.67
Moderate Snow,Blowing Snow12/27/2012 12:00-5.4-6.493410.6100.64
Mostly Cloudy9/9/2012 2:0032.424.41008348.3103.65
Rain9/5/2012 2:0022.820.4995248.3102.26
Rain Showers9/8/2012 16:0026.423.0974148.3102.31
Rain Showers,Fog10/20/2012 3:0012.812.196136.499.83
Rain Showers,Snow Showers12/5/2012 10:002.2-1.2782824.1101.11
Rain,Fog9/30/2012 23:0021.719.5100469.7101.77
Rain,Haze3/13/2012 9:005.52.986179.7100.61
Rain,Ice Pellets12/18/2012 5:000.6-0.692249.7100.12
Rain,Snow4/23/2012 3:001.70.5945225.0101.07
Rain,Snow Grains12/21/2012 0:001.9-2.1752625.0100.60
Rain,Snow,Fog12/8/2012 21:000.80.39696.4100.73
Rain,Snow,Ice Pellets12/21/2012 5:001.30.194286.4100.47
Snow4/27/2012 9:003.70.3965725.0102.73
Snow Pellets11/24/2012 15:000.7-6.459352.499.70
Snow Showers3/4/2012 21:002.9-0.7943748.3102.50
Snow Showers,Fog12/29/2012 13:00-10.0-11.192229.7102.52
Snow,Blowing Snow2/25/2012 9:00-1.4-2.991489.7100.62
Snow,Fog3/14/2012 19:001.10.899359.7102.07
Snow,Haze2/1/2012 21:00-3.6-6.481156.4100.99
Snow,Ice Pellets3/3/2012 4:000.8-1.7923311.3100.96
Thunderstorms7/4/2012 16:0026.720.1871525.0100.62
Thunderstorms,Heavy Rain Showers5/29/2012 6:0010.99.08892.4100.26
Thunderstorms,Moderate Rain Showers,Fog7/17/2012 6:0019.618.593153.2100.01
Thunderstorms,Rain7/23/2012 18:0021.319.1933024.1100.83
Thunderstorms,Rain Showers9/8/2012 4:0025.523.1983225.0101.06
Thunderstorms,Rain Showers,Fog7/31/2012 20:0022.921.391359.7100.64
Thunderstorms,Rain,Fog7/17/2012 5:0020.618.688194.8100.08
\n", + "
" + ], + "text/plain": [ + " Date/Time Temp_C \\\n", + "Weather Condition \n", + "Clear 9/9/2012 5:00 32.8 \n", + "Cloudy 9/9/2012 23:00 30.5 \n", + "Drizzle 9/30/2012 3:00 18.8 \n", + "Drizzle,Fog 9/30/2012 2:00 19.9 \n", + "Drizzle,Ice Pellets,Fog 12/17/2012 9:00 0.4 \n", + "Drizzle,Snow 12/19/2012 18:00 1.2 \n", + "Drizzle,Snow,Fog 12/22/2012 3:00 1.1 \n", + "Fog 9/22/2012 0:00 20.8 \n", + "Freezing Drizzle 2/1/2012 5:00 -2.3 \n", + "Freezing Drizzle,Fog 12/10/2012 5:00 -0.3 \n", + "Freezing Drizzle,Haze 2/1/2012 13:00 -5.0 \n", + "Freezing Drizzle,Snow 3/2/2012 12:00 -3.3 \n", + "Freezing Fog 3/17/2012 6:00 -0.1 \n", + "Freezing Rain 2/1/2012 7:00 0.3 \n", + "Freezing Rain,Fog 12/17/2012 1:00 0.1 \n", + "Freezing Rain,Haze 2/1/2012 15:00 -4.9 \n", + "Freezing Rain,Ice Pellets,Fog 12/17/2012 3:00 -2.6 \n", + "Freezing Rain,Snow Grains 1/13/2012 9:00 -5.0 \n", + "Haze 3/13/2012 23:00 14.1 \n", + "Mainly Clear 9/9/2012 9:00 33.0 \n", + "Moderate Rain,Fog 12/10/2012 8:00 1.7 \n", + "Moderate Snow 12/27/2012 9:00 -4.9 \n", + "Moderate Snow,Blowing Snow 12/27/2012 12:00 -5.4 \n", + "Mostly Cloudy 9/9/2012 2:00 32.4 \n", + "Rain 9/5/2012 2:00 22.8 \n", + "Rain Showers 9/8/2012 16:00 26.4 \n", + "Rain Showers,Fog 10/20/2012 3:00 12.8 \n", + "Rain Showers,Snow Showers 12/5/2012 10:00 2.2 \n", + "Rain,Fog 9/30/2012 23:00 21.7 \n", + "Rain,Haze 3/13/2012 9:00 5.5 \n", + "Rain,Ice Pellets 12/18/2012 5:00 0.6 \n", + "Rain,Snow 4/23/2012 3:00 1.7 \n", + "Rain,Snow Grains 12/21/2012 0:00 1.9 \n", + "Rain,Snow,Fog 12/8/2012 21:00 0.8 \n", + "Rain,Snow,Ice Pellets 12/21/2012 5:00 1.3 \n", + "Snow 4/27/2012 9:00 3.7 \n", + "Snow Pellets 11/24/2012 15:00 0.7 \n", + "Snow Showers 3/4/2012 21:00 2.9 \n", + "Snow Showers,Fog 12/29/2012 13:00 -10.0 \n", + "Snow,Blowing Snow 2/25/2012 9:00 -1.4 \n", + "Snow,Fog 3/14/2012 19:00 1.1 \n", + "Snow,Haze 2/1/2012 21:00 -3.6 \n", + "Snow,Ice Pellets 3/3/2012 4:00 0.8 \n", + "Thunderstorms 7/4/2012 16:00 26.7 \n", + "Thunderstorms,Heavy Rain Showers 5/29/2012 6:00 10.9 \n", + "Thunderstorms,Moderate Rain Showers,Fog 7/17/2012 6:00 19.6 \n", + "Thunderstorms,Rain 7/23/2012 18:00 21.3 \n", + "Thunderstorms,Rain Showers 9/8/2012 4:00 25.5 \n", + "Thunderstorms,Rain Showers,Fog 7/31/2012 20:00 22.9 \n", + "Thunderstorms,Rain,Fog 7/17/2012 5:00 20.6 \n", + "\n", + " Dew Point Temp_C Rel Hum_% \\\n", + "Weather Condition \n", + "Clear 20.4 99 \n", + "Cloudy 22.6 99 \n", + "Drizzle 17.7 96 \n", + "Drizzle,Fog 19.1 100 \n", + "Drizzle,Ice Pellets,Fog -0.7 92 \n", + "Drizzle,Snow 0.2 95 \n", + "Drizzle,Snow,Fog 0.6 98 \n", + "Fog 19.6 100 \n", + "Freezing Drizzle -3.3 93 \n", + "Freezing Drizzle,Fog -2.3 94 \n", + "Freezing Drizzle,Haze -7.7 83 \n", + "Freezing Drizzle,Snow -4.6 94 \n", + "Freezing Fog -0.3 99 \n", + "Freezing Rain -1.7 92 \n", + "Freezing Rain,Fog -0.9 93 \n", + "Freezing Rain,Haze -7.4 83 \n", + "Freezing Rain,Ice Pellets,Fog -3.7 92 \n", + "Freezing Rain,Snow Grains -7.3 84 \n", + "Haze 11.1 86 \n", + "Mainly Clear 21.2 99 \n", + "Moderate Rain,Fog 0.8 94 \n", + "Moderate Snow -6.7 93 \n", + "Moderate Snow,Blowing Snow -6.4 93 \n", + "Mostly Cloudy 24.4 100 \n", + "Rain 20.4 99 \n", + "Rain Showers 23.0 97 \n", + "Rain Showers,Fog 12.1 96 \n", + "Rain Showers,Snow Showers -1.2 78 \n", + "Rain,Fog 19.5 100 \n", + "Rain,Haze 2.9 86 \n", + "Rain,Ice Pellets -0.6 92 \n", + "Rain,Snow 0.5 94 \n", + "Rain,Snow Grains -2.1 75 \n", + "Rain,Snow,Fog 0.3 96 \n", + "Rain,Snow,Ice Pellets 0.1 94 \n", + "Snow 0.3 96 \n", + "Snow Pellets -6.4 59 \n", + "Snow Showers -0.7 94 \n", + "Snow Showers,Fog -11.1 92 \n", + "Snow,Blowing Snow -2.9 91 \n", + "Snow,Fog 0.8 99 \n", + "Snow,Haze -6.4 81 \n", + "Snow,Ice Pellets -1.7 92 \n", + "Thunderstorms 20.1 87 \n", + "Thunderstorms,Heavy Rain Showers 9.0 88 \n", + "Thunderstorms,Moderate Rain Showers,Fog 18.5 93 \n", + "Thunderstorms,Rain 19.1 93 \n", + "Thunderstorms,Rain Showers 23.1 98 \n", + "Thunderstorms,Rain Showers,Fog 21.3 91 \n", + "Thunderstorms,Rain,Fog 18.6 88 \n", + "\n", + " Wind Speed_km/h Visibility_km \\\n", + "Weather Condition \n", + "Clear 33 48.3 \n", + "Cloudy 54 48.3 \n", + "Drizzle 30 25.0 \n", + "Drizzle,Fog 28 9.7 \n", + "Drizzle,Ice Pellets,Fog 20 4.0 \n", + "Drizzle,Snow 19 11.3 \n", + "Drizzle,Snow,Fog 32 9.7 \n", + "Fog 22 9.7 \n", + "Freezing Drizzle 26 12.9 \n", + "Freezing Drizzle,Fog 33 8.0 \n", + "Freezing Drizzle,Haze 11 4.0 \n", + "Freezing Drizzle,Snow 24 12.9 \n", + "Freezing Fog 9 0.8 \n", + "Freezing Rain 28 16.1 \n", + "Freezing Rain,Fog 26 9.7 \n", + "Freezing Rain,Haze 9 2.8 \n", + "Freezing Rain,Ice Pellets,Fog 28 8.0 \n", + "Freezing Rain,Snow Grains 32 4.8 \n", + "Haze 17 9.7 \n", + "Mainly Clear 63 48.3 \n", + "Moderate Rain,Fog 17 6.4 \n", + "Moderate Snow 39 0.8 \n", + "Moderate Snow,Blowing Snow 41 0.6 \n", + "Mostly Cloudy 83 48.3 \n", + "Rain 52 48.3 \n", + "Rain Showers 41 48.3 \n", + "Rain Showers,Fog 13 6.4 \n", + "Rain Showers,Snow Showers 28 24.1 \n", + "Rain,Fog 46 9.7 \n", + "Rain,Haze 17 9.7 \n", + "Rain,Ice Pellets 24 9.7 \n", + "Rain,Snow 52 25.0 \n", + "Rain,Snow Grains 26 25.0 \n", + "Rain,Snow,Fog 9 6.4 \n", + "Rain,Snow,Ice Pellets 28 6.4 \n", + "Snow 57 25.0 \n", + "Snow Pellets 35 2.4 \n", + "Snow Showers 37 48.3 \n", + "Snow Showers,Fog 22 9.7 \n", + "Snow,Blowing Snow 48 9.7 \n", + "Snow,Fog 35 9.7 \n", + "Snow,Haze 15 6.4 \n", + "Snow,Ice Pellets 33 11.3 \n", + "Thunderstorms 15 25.0 \n", + "Thunderstorms,Heavy Rain Showers 9 2.4 \n", + "Thunderstorms,Moderate Rain Showers,Fog 15 3.2 \n", + "Thunderstorms,Rain 30 24.1 \n", + "Thunderstorms,Rain Showers 32 25.0 \n", + "Thunderstorms,Rain Showers,Fog 35 9.7 \n", + "Thunderstorms,Rain,Fog 19 4.8 \n", + "\n", + " Press_kPa \n", + "Weather Condition \n", + "Clear 103.63 \n", + "Cloudy 103.65 \n", + "Drizzle 101.56 \n", + "Drizzle,Fog 102.07 \n", + "Drizzle,Ice Pellets,Fog 100.79 \n", + "Drizzle,Snow 101.15 \n", + "Drizzle,Snow,Fog 100.15 \n", + "Fog 103.04 \n", + "Freezing Drizzle 101.02 \n", + "Freezing Drizzle,Fog 101.27 \n", + "Freezing Drizzle,Haze 100.36 \n", + "Freezing Drizzle,Snow 101.18 \n", + "Freezing Fog 102.85 \n", + "Freezing Rain 101.00 \n", + "Freezing Rain,Fog 101.01 \n", + "Freezing Rain,Haze 100.41 \n", + "Freezing Rain,Ice Pellets,Fog 100.95 \n", + "Freezing Rain,Snow Grains 98.56 \n", + "Haze 102.97 \n", + "Mainly Clear 103.59 \n", + "Moderate Rain,Fog 99.98 \n", + "Moderate Snow 100.67 \n", + "Moderate Snow,Blowing Snow 100.64 \n", + "Mostly Cloudy 103.65 \n", + "Rain 102.26 \n", + "Rain Showers 102.31 \n", + "Rain Showers,Fog 99.83 \n", + "Rain Showers,Snow Showers 101.11 \n", + "Rain,Fog 101.77 \n", + "Rain,Haze 100.61 \n", + "Rain,Ice Pellets 100.12 \n", + "Rain,Snow 101.07 \n", + "Rain,Snow Grains 100.60 \n", + "Rain,Snow,Fog 100.73 \n", + "Rain,Snow,Ice Pellets 100.47 \n", + "Snow 102.73 \n", + "Snow Pellets 99.70 \n", + "Snow Showers 102.50 \n", + "Snow Showers,Fog 102.52 \n", + "Snow,Blowing Snow 100.62 \n", + "Snow,Fog 102.07 \n", + "Snow,Haze 100.99 \n", + "Snow,Ice Pellets 100.96 \n", + "Thunderstorms 100.62 \n", + "Thunderstorms,Heavy Rain Showers 100.26 \n", + "Thunderstorms,Moderate Rain Showers,Fog 100.01 \n", + "Thunderstorms,Rain 100.83 \n", + "Thunderstorms,Rain Showers 101.06 \n", + "Thunderstorms,Rain Showers,Fog 100.64 \n", + "Thunderstorms,Rain,Fog 100.08 " + ] + }, + "execution_count": 73, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.groupby('Weather Condition').max()" + ] + }, + { + "cell_type": "markdown", + "id": "3398d07f", + "metadata": {}, + "source": [ + "## Q) 13. Show all the Records where Weather Condiiton is Fog." + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "id": "7b49e663", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Date/TimeTemp_CDew Point Temp_CRel Hum_%Wind Speed_km/hVisibility_kmPress_kPaWeather Condition
01/1/2012 0:00-1.8-3.98648.0101.24Fog
11/1/2012 1:00-1.8-3.78748.0101.24Fog
41/1/2012 4:00-1.5-3.38874.8101.23Fog
51/1/2012 5:00-1.4-3.38796.4101.27Fog
61/1/2012 6:00-1.5-3.18976.4101.29Fog
...........................
871612/29/2012 4:00-16.0-17.29069.7101.25Fog
871712/29/2012 5:00-14.8-15.99146.4101.25Fog
871812/29/2012 6:00-13.8-15.38849.7101.25Fog
871912/29/2012 7:00-14.8-16.48878.0101.22Fog
872212/29/2012 10:00-12.0-13.39076.4101.15Fog
\n", + "

150 rows × 8 columns

\n", + "
" + ], + "text/plain": [ + " Date/Time Temp_C Dew Point Temp_C Rel Hum_% Wind Speed_km/h \\\n", + "0 1/1/2012 0:00 -1.8 -3.9 86 4 \n", + "1 1/1/2012 1:00 -1.8 -3.7 87 4 \n", + "4 1/1/2012 4:00 -1.5 -3.3 88 7 \n", + "5 1/1/2012 5:00 -1.4 -3.3 87 9 \n", + "6 1/1/2012 6:00 -1.5 -3.1 89 7 \n", + "... ... ... ... ... ... \n", + "8716 12/29/2012 4:00 -16.0 -17.2 90 6 \n", + "8717 12/29/2012 5:00 -14.8 -15.9 91 4 \n", + "8718 12/29/2012 6:00 -13.8 -15.3 88 4 \n", + "8719 12/29/2012 7:00 -14.8 -16.4 88 7 \n", + "8722 12/29/2012 10:00 -12.0 -13.3 90 7 \n", + "\n", + " Visibility_km Press_kPa Weather Condition \n", + "0 8.0 101.24 Fog \n", + "1 8.0 101.24 Fog \n", + "4 4.8 101.23 Fog \n", + "5 6.4 101.27 Fog \n", + "6 6.4 101.29 Fog \n", + "... ... ... ... \n", + "8716 9.7 101.25 Fog \n", + "8717 6.4 101.25 Fog \n", + "8718 9.7 101.25 Fog \n", + "8719 8.0 101.22 Fog \n", + "8722 6.4 101.15 Fog \n", + "\n", + "[150 rows x 8 columns]" + ] + }, + "execution_count": 75, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data[data['Weather Condition'] == 'Fog']" + ] + }, + { + "cell_type": "markdown", + "id": "c0a1a49e", + "metadata": {}, + "source": [ + "## Q) 14. Find all instances when 'Weather is Clear' or 'Visibility is above 40'." + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "id": "2a734aec", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Date/TimeTemp_CDew Point Temp_CRel Hum_%Wind Speed_km/hVisibility_kmPress_kPaWeather Condition
671/3/2012 19:00-16.9-24.8502425.0101.74Clear
1061/5/2012 10:00-6.0-10.0731748.3100.45Mainly Clear
1071/5/2012 11:00-5.6-10.2702248.3100.41Mainly Clear
1081/5/2012 12:00-4.7-9.6692048.3100.38Mainly Clear
1091/5/2012 13:00-4.4-9.7662648.3100.40Mainly Clear
...........................
874912/30/2012 13:00-12.4-16.2733748.3100.92Mostly Cloudy
875012/30/2012 14:00-11.8-16.1703748.3100.96Mainly Clear
875112/30/2012 15:00-11.3-15.6703248.3101.05Mainly Clear
875212/30/2012 16:00-11.4-15.5722648.3101.15Mainly Clear
875612/30/2012 20:00-13.8-16.5802425.0101.52Clear
\n", + "

3027 rows × 8 columns

\n", + "
" + ], + "text/plain": [ + " Date/Time Temp_C Dew Point Temp_C Rel Hum_% Wind Speed_km/h \\\n", + "67 1/3/2012 19:00 -16.9 -24.8 50 24 \n", + "106 1/5/2012 10:00 -6.0 -10.0 73 17 \n", + "107 1/5/2012 11:00 -5.6 -10.2 70 22 \n", + "108 1/5/2012 12:00 -4.7 -9.6 69 20 \n", + "109 1/5/2012 13:00 -4.4 -9.7 66 26 \n", + "... ... ... ... ... ... \n", + "8749 12/30/2012 13:00 -12.4 -16.2 73 37 \n", + "8750 12/30/2012 14:00 -11.8 -16.1 70 37 \n", + "8751 12/30/2012 15:00 -11.3 -15.6 70 32 \n", + "8752 12/30/2012 16:00 -11.4 -15.5 72 26 \n", + "8756 12/30/2012 20:00 -13.8 -16.5 80 24 \n", + "\n", + " Visibility_km Press_kPa Weather Condition \n", + "67 25.0 101.74 Clear \n", + "106 48.3 100.45 Mainly Clear \n", + "107 48.3 100.41 Mainly Clear \n", + "108 48.3 100.38 Mainly Clear \n", + "109 48.3 100.40 Mainly Clear \n", + "... ... ... ... \n", + "8749 48.3 100.92 Mostly Cloudy \n", + "8750 48.3 100.96 Mainly Clear \n", + "8751 48.3 101.05 Mainly Clear \n", + "8752 48.3 101.15 Mainly Clear \n", + "8756 25.0 101.52 Clear \n", + "\n", + "[3027 rows x 8 columns]" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data[(data['Weather Condition'] == 'Clear') | (data['Visibility_km'] > 40)]" + ] + }, + { + "cell_type": "markdown", + "id": "2859c52b", + "metadata": {}, + "source": [ + "## Q) 15. Find all instances when:" + ] + }, + { + "cell_type": "markdown", + "id": "14f7c004", + "metadata": {}, + "source": [ + "### A. 'Weather is Clear' and 'Relative Humidity is greater than 50'" + ] + }, + { + "cell_type": "markdown", + "id": "535e6af2", + "metadata": {}, + "source": [ + "### or" + ] + }, + { + "cell_type": "markdown", + "id": "85c65840", + "metadata": {}, + "source": [ + "### B. 'Visibilty is above 40'" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "id": "c6f5ff95", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Date/TimeTemp_CDew Point Temp_CRel Hum_%Wind Speed_km/hVisibility_kmPress_kPaWeather Condition
1061/5/2012 10:00-6.0-10.0731748.3100.45Mainly Clear
1071/5/2012 11:00-5.6-10.2702248.3100.41Mainly Clear
1081/5/2012 12:00-4.7-9.6692048.3100.38Mainly Clear
1091/5/2012 13:00-4.4-9.7662648.3100.40Mainly Clear
1101/5/2012 14:00-5.1-10.7652248.3100.46Mainly Clear
...........................
874912/30/2012 13:00-12.4-16.2733748.3100.92Mostly Cloudy
875012/30/2012 14:00-11.8-16.1703748.3100.96Mainly Clear
875112/30/2012 15:00-11.3-15.6703248.3101.05Mainly Clear
875212/30/2012 16:00-11.4-15.5722648.3101.15Mainly Clear
875612/30/2012 20:00-13.8-16.5802425.0101.52Clear
\n", + "

2921 rows × 8 columns

\n", + "
" + ], + "text/plain": [ + " Date/Time Temp_C Dew Point Temp_C Rel Hum_% Wind Speed_km/h \\\n", + "106 1/5/2012 10:00 -6.0 -10.0 73 17 \n", + "107 1/5/2012 11:00 -5.6 -10.2 70 22 \n", + "108 1/5/2012 12:00 -4.7 -9.6 69 20 \n", + "109 1/5/2012 13:00 -4.4 -9.7 66 26 \n", + "110 1/5/2012 14:00 -5.1 -10.7 65 22 \n", + "... ... ... ... ... ... \n", + "8749 12/30/2012 13:00 -12.4 -16.2 73 37 \n", + "8750 12/30/2012 14:00 -11.8 -16.1 70 37 \n", + "8751 12/30/2012 15:00 -11.3 -15.6 70 32 \n", + "8752 12/30/2012 16:00 -11.4 -15.5 72 26 \n", + "8756 12/30/2012 20:00 -13.8 -16.5 80 24 \n", + "\n", + " Visibility_km Press_kPa Weather Condition \n", + "106 48.3 100.45 Mainly Clear \n", + "107 48.3 100.41 Mainly Clear \n", + "108 48.3 100.38 Mainly Clear \n", + "109 48.3 100.40 Mainly Clear \n", + "110 48.3 100.46 Mainly Clear \n", + "... ... ... ... \n", + "8749 48.3 100.92 Mostly Cloudy \n", + "8750 48.3 100.96 Mainly Clear \n", + "8751 48.3 101.05 Mainly Clear \n", + "8752 48.3 101.15 Mainly Clear \n", + "8756 25.0 101.52 Clear \n", + "\n", + "[2921 rows x 8 columns]" + ] + }, + "execution_count": 80, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data[(data['Weather Condition'] == 'Clear') & (data['Rel Hum_%'] > 50) | (data['Visibility_km'] > 40)]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "76eb7a0a", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.0" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/download_project.py b/download_project.py new file mode 100644 index 0000000..085ce96 --- /dev/null +++ b/download_project.py @@ -0,0 +1,58 @@ +# Program to automate to clear my downloads folder + +import os +from pprint import pprint +import collections + +video_extension = ['mp4','mpg', 'mpeg', 'avi', 'mov', 'flv', 'mwv', 'm4v', 'mkv', 'h264'] +audio_extension = ['mp3', 'wav', 'raw', 'wma', 'mid', 'midi'] +image_extension = ['png', 'jpg', 'jpeg', 'gif', 'svg', 'bmp', 'psd', 'tif', 'tiff' ] +document_extension = ['txt','pdf', 'csv', 'xls', 'xlsx', 'ods', 'doc', 'docx','html', 'odt', 'tex', 'ppt', 'pptx', 'log'] +compression_extension = ['zip', 'z', 'tar', '7z', 'rar', 'gz', 'bz', 'rpm', 'pkg', 'deb'] +install_extension = ['dmg', 'exe', 'iso'] + +# step 1 - (Optional) Create directories where we want to store the files +base_path = os.path.expanduser("~") +print(base_path) +dest_dirs = ['video_folder', 'audio_folder', 'image_folder', 'document_folder', 'compression_folder', 'other_folder'] + +for d in dest_dirs: + dir_path = os.path.join(base_path, d) + if not os.path.isdir(dir_path): + os.mkdir(dir_path) + +download_path = os.path.join(base_path, 'Downloads') +files_mapping = collections.defaultdict(list) +files_list = os.listdir(download_path) + +# Step 2 - Map files from Downloads folder based on their file extension +for filename in files_list: + if filename != '.': + file_ext = filename.split('.')[-1] + files_mapping[file_ext].append(filename) + +pprint(files_mapping) + +# Step 3 - Move all files given a file extension to a target directory +for f_ext, f_list in files_mapping.items(): + if f_ext in video_extension: + for file in f_list: + os.rename(os.path.join(download_path, file), os.path.join(base_path, 'video_folder', file)) + elif f_ext in audio_extension: + for file in f_list: + os.rename(os.path.join(download_path, file), os.path.join(base_path, 'audio_folder', file)) + elif f_ext in image_extension: + for file in f_list: + os.rename(os.path.join(download_path, file), os.path.join(base_path, 'image_folder', file)) + elif f_ext in document_extension: + for file in f_list: + os.rename(os.path.join(download_path, file), os.path.join(base_path, 'document_folder', file)) + elif f_ext in compression_extension: + for file in f_list: + os.rename(os.path.join(download_path, file), os.path.join(base_path, 'compression_folder', file)) + elif f_ext in install_extension: + for file in f_list: + os.rename(os.path.join(download_path, file), os.path.join(base_path, 'installation_folder', file)) + else: + for file in f_list: + os.rename(os.path.join(download_path, file), os.path.join(base_path, 'other_folder', file)) diff --git a/filtered_user_file.json b/filtered_user_file.json new file mode 100644 index 0000000..43af21d --- /dev/null +++ b/filtered_user_file.json @@ -0,0 +1,52 @@ +[ + { + "id": 5, + "name": "Chelsey Dietrich", + "phone": "(254)954-1289" + }, + { + "id": 10, + "name": "Clementina DuBuque", + "phone": "024-648-3804" + }, + { + "id": 3, + "name": "Clementine Bauch", + "phone": "1-463-123-4447" + }, + { + "id": 2, + "name": "Ervin Howell", + "phone": "010-692-6593 x09125" + }, + { + "id": 9, + "name": "Glenna Reichert", + "phone": "(775)976-6794 x41206" + }, + { + "id": 7, + "name": "Kurtis Weissnat", + "phone": "210.067.6132" + }, + { + "id": 1, + "name": "Leanne Graham", + "phone": "1-770-736-8031 x56442" + }, + { + "id": 6, + "name": "Mrs. Dennis Schulist", + "phone": "1-477-935-8478 x6430" + }, + { + "id": 8, + "name": "Nicholas Runolfsdottir V", + "phone": "586.493.6943 x140" + }, + { + "id": 4, + "name": "Patricia Lebsack", + "phone": "493-170-9623 x156" + } +] \ No newline at end of file diff --git a/movies.xml b/movies.xml new file mode 100644 index 0000000..f3c9c4c --- /dev/null +++ b/movies.xml @@ -0,0 +1,127 @@ + + + + + DVD + 1981 + PG + + 'Archaeologist and adventurer Indiana Jones + is hired by the U.S. government to find the Ark of the + Covenant before the Nazis.' + + + + DVD,Online + 1984 + PG + None provided. + + + Blu-ray + 1985 + PG + Marty McFly + + + + + Online + 1992 + R + WhAtEvER I Want!!!?! + + + + dvd, digital + 2000 + PG-13 + Two mutants come to a private academy for their kind whose resident superhero team must + oppose a terrorist organization with similar powers. + + + + + + + DVD + 1979 + R + """"""""" + + + + + DVD + 1986 + PG13 + Funny movie about a funny guy + + + blue-ray + 2000 + Unrated + psychopathic Bateman + + + + + + + + DVD,VHS + 1966 + PG + What a joke! + + + + + DVD + 2010 + PG--13 + Emma Stone = Hester Prynne + + + DVD,digital,Netflix + 2011 + Unrated + Tim (Rudd) is a rising executive + who 'succeeds' in finding the perfect guest, + IRS employee Barry (Carell), for his boss' monthly event, + a so-called 'dinner for idiots,' which offers certain + advantages to the exec who shows up with the biggest buffoon. + + + + + + Online,VHS + 1984 + PG + Who ya gonna call? + + + + + Blu_Ray + 1991 + Unknown + Robin Hood slaying + + + + + + + DVD + 2000s + R + A former Roman General sets out to exact vengeance against the corrupt emperor who murdered his family and sent him into slavery. + + VHS + 1992 + PG13 + NA. + + \ No newline at end of file diff --git a/phnumber.py b/phnumber.py new file mode 100644 index 0000000..2ca2c45 --- /dev/null +++ b/phnumber.py @@ -0,0 +1,19 @@ +# Getting the location and service provider for a phone number + +import phonenumbers +from phonenumbers import geocoder, carrier, timezone + +# Getting the phone number aw input +number = input("Please enter your Phone Number: ") + +# Getting the name of the place for the Phone number +ch_number = phonenumbers.parse(number, "CH") +print(geocoder.description_for_number(ch_number, "en")) + +# Getting the Service provider for the Phone number +service_number = phonenumbers.parse(number, "RO") +print(carrier.name_for_number(service_number, "en")) + +# Getting the Timezone for the Phone number +time_number = phonenumbers.parse(number) +print(timezone.time_zones_for_number(time_number)) diff --git a/regex_practice_exercises.ipynb b/regex_practice_exercises.ipynb new file mode 100644 index 0000000..2df3ccf --- /dev/null +++ b/regex_practice_exercises.ipynb @@ -0,0 +1,1368 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "lbrLwTw4r9jM" + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "mtZQDWxxos3J" + }, + "source": [ + "# 30 REGULAR EXPRESSION EXERCISES!" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "6jEYHJH3os3Q" + }, + "source": [ + "Regex, you never know when they might come in handy. It's one of the \"good programmer\"'s fundamental yet a few people actually masters them.\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "id": "ghj1l7sQos3R", + "trusted": true + }, + "outputs": [], + "source": [ + "import re" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "_tO-OHUBos3T" + }, + "source": [ + "1) Write a Python program to check that a string contains only a certain set of characters (in this case a-z, A-Z and 0-9)." + ] + }, + { + "cell_type": "code", + "execution_count": 416, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "cXaMTykzos3V", + "outputId": "a73c9558-3ac4-44e9-ad0f-685a8f627983", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n" + ] + } + ], + "source": [ + "# Solution\n", + "def is_allowed_specific_char(text):\n", + " # Define a regex pattern\n", + " pattern = r'[a-zA-Z0-9]+'\n", + " # Use the pattern to search for ....\n", + " result = re.search(pattern, text)\n", + " if result is None:\n", + " return False\n", + " else:\n", + " return True\n", + " \n", + "print(is_allowed_specific_char(\"ABCDEFabcdef123450\")) # True\n", + "print(is_allowed_specific_char(\"*&%@#!}{\")) # False" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "2oae-B8tos3W" + }, + "source": [ + "2) Write a Python program that matches a string that has an a followed by zero or more b's" + ] + }, + { + "cell_type": "code", + "execution_count": 412, + "metadata": { + "id": "1LHEOOMkos3X", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found a Match!\n", + "Found a Match!\n", + "Found a Match!\n", + "Not Matched\n" + ] + } + ], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " result = re.match(r'ab?', text)\n", + " if result is None:\n", + " return 'Not Matched'\n", + " else: \n", + " return 'Found a Match!' \n", + " #pass\n", + "\n", + "print(text_match(\"ac\")) # Found a match!\n", + "print(text_match(\"abc\")) # Found a match!\n", + "print(text_match(\"abbc\")) # Found a match!\n", + "print(text_match(\"bbc\")) # Not matched" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "AQRTCmJZos3Z" + }, + "source": [ + "3) Write a Python program that matches a string that has an a followed by one or more b's" + ] + }, + { + "cell_type": "code", + "execution_count": 411, + "metadata": { + "id": "H1X2NPQYos3a", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found a Match\n", + "Found a Match\n", + "Not Matched\n", + "Not Matched\n" + ] + } + ], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " result = re.match(r'ab+', text)\n", + " if result is None:\n", + " return 'Not Matched'\n", + " else: \n", + " return 'Found a Match' \n", + " #pass\n", + "\n", + "print(text_match(\"ab\")) # Found a match!\n", + "print(text_match(\"abc\")) # Found a match!\n", + "print(text_match(\"ac\")) # Not matched\n", + "print(text_match(\"bbc\")) # Not matched" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "E902uTcRos3a" + }, + "source": [ + "4) Write a Python program that matches a string that has an a followed by zero or one 'b'" + ] + }, + { + "cell_type": "code", + "execution_count": 410, + "metadata": { + "id": "xeva0fRNos3b", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found a Match\n", + "Found a Match\n", + "Found a Match\n", + "Found a Match\n", + "Found a Match\n", + "Not Matched\n" + ] + } + ], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " result = re.search(r'ab{0,1}', text)\n", + " if result is None:\n", + " return 'Not Matched'\n", + " else: \n", + " return 'Found a Match' \n", + " #pass\n", + " \n", + "print(text_match(\"ab\")) # Found a match!\n", + "print(text_match(\"abc\")) # Found a match!\n", + "print(text_match(\"abbc\")) # Found a match!\n", + "print(text_match(\"aabbc\")) # Found a match!\n", + "print(text_match(\"ac\")) # Found a match!\n", + "print(text_match(\"bbc\")) # Not matched" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "whnPaW2kos3c" + }, + "source": [ + "5) Write a Python program that matches a string that has an a followed by three 'b'" + ] + }, + { + "cell_type": "code", + "execution_count": 406, + "metadata": { + "id": "0c_7S3h_os3d", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found a Match\n", + "Found a Match\n", + "Not Matched\n", + "Not Matched\n", + "Not Matched\n" + ] + } + ], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " result = re.search(r'ab{3}', text)\n", + " if result is None:\n", + " return 'Not Matched'\n", + " else: \n", + " return 'Found a Match' \n", + " #pass\n", + "\n", + "print(text_match(\"abbb\")) # Found a match!\n", + "print(text_match(\"aabbbbbc\")) # Found a match!\n", + "print(text_match(\"aabbc\")) # Not matched\n", + "print(text_match(\"ac\")) # Not matched\n", + "print(text_match(\"bbc\")) # Not matched" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "V4AsjJiCos3e" + }, + "source": [ + "6) Write a Python program that matches a string that has an a followed by two to three 'b'." + ] + }, + { + "cell_type": "code", + "execution_count": 403, + "metadata": { + "id": "VjA5CXi1os3e", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Not Matched\n", + "Found a Match\n", + "Found a Match\n", + "Not Matched\n", + "Not Matched\n" + ] + } + ], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " result = re.search(r'ab{2,3}', text)\n", + " if result is None:\n", + " return 'Not Matched'\n", + " else: \n", + " return 'Found a Match' \n", + " #pass\n", + "\n", + "print(text_match(\"ab\")) # Not matched\n", + "print(text_match(\"aabbbbbc\")) # Found a match!\n", + "print(text_match(\"aabbc\")) # Found a match!\n", + "print(text_match(\"ac\")) # Not matched\n", + "print(text_match(\"bbc\")) # Not matched" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "kX7sLRavos3f" + }, + "source": [ + "7) Write a Python program to find sequences of lowercase letters joined with a underscore." + ] + }, + { + "cell_type": "code", + "execution_count": 401, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "rbxk35n7os3g", + "outputId": "3ddca986-1bd6-45f1-902c-eee85e8853e8", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found a Match\n", + "Not Matched\n", + "Not Matched\n" + ] + } + ], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " #pass\n", + " result = re.search(r'^[a-z]+_[a-z]+$', text)\n", + " if result is None:\n", + " return 'Not Matched'\n", + " else: \n", + " return 'Found a Match' \n", + "\n", + "print(text_match(\"aab_cbbbc\")) # Found a match!\n", + "print(text_match(\"aab_Abbbc\")) # Not matched\n", + "print(text_match(\"Aaab_abbbc\")) # Not matched" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "H4sat-Rfos3g" + }, + "source": [ + "8) Write a Python program to find the sequences of one upper case letter followed by lower case letters." + ] + }, + { + "cell_type": "code", + "execution_count": 399, + "metadata": { + "id": "oeUiVHGVos3h", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Not Matched\n", + "Found a Match\n", + "Found a Match\n" + ] + } + ], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " #pass\n", + " result = re.search(r'[A-Z][a-z]+', text)\n", + " if result is None:\n", + " return 'Not Matched'\n", + " else: \n", + " return 'Found a Match' \n", + "\n", + "print(text_match(\"aab_cbbbc\")) # Not matched\n", + "print(text_match(\"aab_Abbbc\")) # Found a match!\n", + "print(text_match(\"Aaab_abbbc\")) # Found a match!" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "RgNBl7aEos3h" + }, + "source": [ + "9) Write a Python program that matches a string that has an 'a' followed by anything, ending in 'b'." + ] + }, + { + "cell_type": "code", + "execution_count": 397, + "metadata": { + "id": "YbCsos7Jos3i", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Not Matched\n", + "Not Matched\n", + "Found a Match\n" + ] + } + ], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " #pass\n", + " result = re.match(r'^a.*?b$', text)\n", + " if result is None:\n", + " return 'Not Matched'\n", + " else:\n", + " return 'Found a Match' \n", + "\n", + "print(text_match(\"aabbbbd\")) # Not matched\n", + "print(text_match(\"aabAbbbc\")) # Not matched\n", + "print(text_match(\"accddbbjjjb\")) # Found a match!" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "0oHZnx0Gos3i" + }, + "source": [ + "10) Write a Python program that matches a word at the beginning of a string." + ] + }, + { + "cell_type": "code", + "execution_count": 395, + "metadata": { + "id": "1tlZiGMaos3j", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found a Match\n", + "Not Matched\n" + ] + } + ], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " #pass\n", + " result = re.match(r'^\\w+', text)\n", + " if result is None:\n", + " return 'Not Matched'\n", + " else: \n", + " return 'Found a Match' \n", + "\n", + "print(text_match(\"The quick brown fox jumps over the lazy dog.\")) # Found a match!\n", + "print(text_match(\" The quick brown fox jumps over the lazy dog.\")) # Not matched" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "mG0jspZFos3j" + }, + "source": [ + "11) Write a Python program that matches a word at the end of string, with optional punctuation." + ] + }, + { + "cell_type": "code", + "execution_count": 393, + "metadata": { + "id": "cmhnhbZnos3j", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found a Match\n", + "Not Matched\n", + "Not Matched\n" + ] + } + ], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " #pass\n", + " result = re.search(r'\\w+\\S*$', text)\n", + " if result is None:\n", + " return 'Not Matched'\n", + " else: \n", + " return 'Found a Match' \n", + "\n", + "print(text_match(\"The quick brown fox jumps over the lazy dog.\")) # Found a match!\n", + "print(text_match(\"The quick brown fox jumps over the lazy dog. \")) # Not matched\n", + "print(text_match(\"The quick brown fox jumps over the lazy dog \")) # Not matched" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "DBgbyYHXos3k" + }, + "source": [ + "12) Write a Python program that matches a word containing 'z'" + ] + }, + { + "cell_type": "code", + "execution_count": 392, + "metadata": { + "id": "WxuMRyCbos3k", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found a Match\n", + "Not Matched\n" + ] + } + ], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " #pass\n", + " result = re.search(r'\\w*z.\\w*', text)\n", + " if result is None:\n", + " return 'Not Matched'\n", + " else: \n", + " return 'Found a Match' \n", + "\n", + " \n", + "print(text_match(\"The quick brown fox jumps over the lazy dog.\")) # Found a match!\n", + "print(text_match(\"Python Exercises.\")) # Not matched" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "V_9_nk8Kos3l" + }, + "source": [ + "13) Write a Python program that matches a word containing 'z', not at the start or end of the word." + ] + }, + { + "cell_type": "code", + "execution_count": 389, + "metadata": { + "id": "VEhCCh7yos3l", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found a Match\n", + "Not Matched\n" + ] + } + ], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " #pass\n", + " result = re.search(r'\\Bz\\B', text)\n", + " if result is None:\n", + " return 'Not Matched'\n", + " else: \n", + " return 'Found a Match' \n", + "\n", + "print(text_match(\"The quick brown fox jumps over the lazy dog.\")) # Found a match!\n", + "print(text_match(\"Python Exercises.\")) # Not matched" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "L0lV07OCos3m" + }, + "source": [ + "14) Write a Python program to match a string that contains only upper and lowercase letters, numbers, and underscores." + ] + }, + { + "cell_type": "code", + "execution_count": 388, + "metadata": { + "id": "E9NcoWDhos3m", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Not Matched\n", + "Found a Match\n" + ] + } + ], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " #pass\n", + " result = re.search(r'^[A-Za-z0-9_]*$', text)\n", + " if result is None:\n", + " return 'Not Matched'\n", + " else: \n", + " return 'Found a Match' \n", + "\n", + "print(text_match(\"The quick brown fox jumps over the lazy dog.\")) # Not matched\n", + "print(text_match(\"Python_Exercises_1\")) # Found a match!" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "EvKJ8WOoos3n" + }, + "source": [ + "15) Write a Python program where a string will start with a specific number. " + ] + }, + { + "cell_type": "code", + "execution_count": 383, + "metadata": { + "id": "nWp5QysTos3n", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n" + ] + } + ], + "source": [ + "# Solution\n", + "def match_num(string):\n", + " #pass\n", + " result = re.match(r'^5', string)\n", + " if result is None:\n", + " return False\n", + " else: \n", + " return True \n", + " \n", + "print(match_num('5-2345861')) # True\n", + "print(match_num('6-2345861')) # False" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "r_I1cbvios3t" + }, + "source": [ + "16) Write a Python program to remove leading zeros from an IP address" + ] + }, + { + "cell_type": "code", + "execution_count": 382, + "metadata": { + "id": "cRLX4hc3os3u", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "216.8.94.196\n" + ] + } + ], + "source": [ + "# Solution\n", + "def rewrite_ip(ip):\n", + " # your code here\n", + " result = re.sub(r'\\.0*', '.', ip)\n", + " if result is None:\n", + " return ''\n", + " else: \n", + " return result \n", + " #pass\n", + "\n", + "ip = \"216.08.094.196\"\n", + "string = rewrite_ip(ip)\n", + "print(string) # 216.8.94.196" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ZCn9r3o2os3u" + }, + "source": [ + "17) Write a Python program to check for a number at the end of a string." + ] + }, + { + "cell_type": "code", + "execution_count": 379, + "metadata": { + "id": "Q5t9U6n8os3u", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "True\n" + ] + } + ], + "source": [ + "# Solution\n", + "def end_num(string):\n", + " result = re.search(r'\\d$', string)\n", + " if result is None:\n", + " return False\n", + " else: \n", + " return True\n", + " #pass\n", + "\n", + "print(end_num('abcdef')) # False\n", + "print(end_num('abcdef6')) # True" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "0tM4eW8Wos3v" + }, + "source": [ + "18) Write a Python program to search the numbers (0-9) of length between 1 to 3 in a given string. " + ] + }, + { + "cell_type": "code", + "execution_count": 380, + "metadata": { + "id": "7QGwzVxDos3v", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Number of length 1 to 3\n", + "1\n", + "12\n", + "13\n", + "345\n" + ] + } + ], + "source": [ + "# Solution\n", + "def print_digits(string):\n", + " result = re.finditer(r'([0-9]{1,3})', string)\n", + " if result is None:\n", + " return 'Match not Found'\n", + " else: \n", + " print('Number of length 1 to 3') \n", + " for text in result:\n", + " print(text.group(0))\n", + " \n", + " #pass\n", + "\n", + "string = \"Exercises number 1, 12, 13, and 345 are important\"\n", + "print_digits(string)\n", + "# Number of length 1 to 3\n", + "# 1\n", + "# 12\n", + "# 13\n", + "# 345" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "43nNb7d_os3v" + }, + "source": [ + "19) Write a Python program to search some literals strings in a string. \n", + "Sample text : 'The quick brown fox jumps over the lazy dog.'\n", + "Searched words : 'fox', 'dog', 'horse'" + ] + }, + { + "cell_type": "code", + "execution_count": 375, + "metadata": { + "id": "KIVHxWN9os3w", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Searching for \"fox\" in \"The quick brown fox jumps over the lazy dog.\" ->\n", + "Matched!\n", + "Searching for \"dog\" in \"The quick brown fox jumps over the lazy dog.\" ->\n", + "Matched!\n", + "Searching for \"horse\" in \"The quick brown fox jumps over the lazy dog.\" ->\n", + "Not Matched\n" + ] + } + ], + "source": [ + "# Solution\n", + "def print_match(patterns, text):\n", + " for string in patterns:\n", + " result = re.search(string, text) \n", + " print('Searching for \"{}\" in \"{}\" ->'.format(string, text))\n", + " if result is None:\n", + " print(\"Not Matched\")\n", + " else: \n", + " print(\"Matched!\") \n", + " #pass\n", + "\n", + "\n", + "patterns = [ 'fox', 'dog', 'horse' ]\n", + "text = 'The quick brown fox jumps over the lazy dog.'\n", + "print_match(patterns, text)\n", + "# Searching for \"fox\" in \"The quick brown fox jumps over the lazy dog.\" ->\n", + "# Matched!\n", + "# Searching for \"dog\" in \"The quick brown fox jumps over the lazy dog.\" ->\n", + "# Matched!\n", + "# Searching for \"horse\" in \"The quick brown fox jumps over the lazy dog.\" ->\n", + "# Not Matched!" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "XjdROmMhos3w" + }, + "source": [ + "20) Write a Python program to search a literals string in a string and also find the location within the original string where the pattern occurs\n", + "\n", + "Sample text : 'The quick brown fox jumps over the lazy dog.'\n", + "Searched words : 'fox'" + ] + }, + { + "cell_type": "code", + "execution_count": 374, + "metadata": { + "id": "vWViImYios3w", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found \"fox\" in \"The quick brown fox jumps over the lazy dog.\" from 16 to 19\n" + ] + } + ], + "source": [ + "# Solution\n", + "def print_match_location(pattern, text):\n", + " result = re.search(pattern, text)\n", + " if result is None:\n", + " result = ''\n", + " print('Not Found \"{}\" in \"{}\"'.format(pattern, text))\n", + " else: \n", + " result = result.span() \n", + " print('Found \"{}\" in \"{}\" from {} to {}'.format(pattern, text, result[0], result[1]))\n", + " #pass\n", + "\n", + "pattern = 'fox'\n", + "text = 'The quick brown fox jumps over the lazy dog.'\n", + "print_match_location(pattern, text)\n", + "# Found \"fox\" in \"The quick brown fox jumps over the lazy dog.\" from 16 to 19" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "lLRotk-Oos3x" + }, + "source": [ + "21) Write a Python program to find the substrings within a string.\n", + "\n", + "Sample text :\n", + "\n", + "'Python exercises, PHP exercises, C# exercises'\n", + "\n", + "Pattern :\n", + "\n", + "'exercises'\n", + "\n", + "Note: There are three instances of exercises in the input string." + ] + }, + { + "cell_type": "code", + "execution_count": 373, + "metadata": { + "id": "XU8613rTos3x", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found \"exercises\"\n", + "Found \"exercises\"\n", + "Found \"exercises\"\n" + ] + } + ], + "source": [ + "# Solution\n", + "def find_all_matches(pattern, text):\n", + " result = re.findall(pattern, text)\n", + " if len(result) == 0:\n", + " print('Not Found \"{}\"'.format(pattern))\n", + " else: \n", + " for string in result:\n", + " print('Found \"{}\"'.format(pattern))\n", + " #pass\n", + "\n", + "text = 'Python exercises, PHP exercises, C# exercises'\n", + "pattern = 'exercises'\n", + "find_all_matches(pattern, text)\n", + "# Found \"exercises\"\n", + "# Found \"exercises\"\n", + "# Found \"exercises\"" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "uvAY6v7Oos3x" + }, + "source": [ + "22) Write a Python program to find the occurrence and position of the substrings within a string." + ] + }, + { + "cell_type": "code", + "execution_count": 372, + "metadata": { + "id": "UFg6rXJnos3y", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found \"exercises\" at 7:16\n", + "Found \"exercises\" at 22:31\n", + "Found \"exercises\" at 36:45\n" + ] + } + ], + "source": [ + "# Solution\n", + "def find_all_matches_location(pattern, text):\n", + " result = re.finditer(pattern, text)\n", + " if result is None:\n", + " result = ''\n", + " print('Not Found \"{}\" in \"{}\"'.format(pattern, text))\n", + " else: \n", + " for string in result:\n", + " result1 = string.span() \n", + " print('Found \"{}\" at {}:{}'.format(pattern, result1[0], result1[1]))\n", + "\n", + " #pass\n", + "\n", + "\n", + "text = 'Python exercises, PHP exercises, C# exercises'\n", + "pattern = 'exercises'\n", + "find_all_matches_location(pattern, text)\n", + "# Found \"exercises\" at 7:16\n", + "# Found \"exercises\" at 22:31\n", + "# Found \"exercises\" at 36:45" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Sb3zKxE-os3y" + }, + "source": [ + "23) Write a Python program to replace whitespaces with an underscore and vice versa." + ] + }, + { + "cell_type": "code", + "execution_count": 370, + "metadata": { + "id": "nUxR5Xvjos3z", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Python_Exercises\n", + "Python Exercises\n" + ] + } + ], + "source": [ + "text = 'Python Exercises'\n", + "text = re.sub(r'\\s', '_', text)\n", + "print(text) # Python_Exercises\n", + "text = re.sub('_', ' ', text)\n", + "print(text) # Python Exercises" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "grqoW-pgos3z" + }, + "source": [ + "24) Write a Python program to extract year, month and date from a an url. " + ] + }, + { + "cell_type": "code", + "execution_count": 371, + "metadata": { + "id": "K2-pacqmos3z", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[('2016', '09', '02')]\n" + ] + } + ], + "source": [ + "# Solution\n", + "def extract_date(url):\n", + " result = re.findall(r'/(\\d{4})/(\\d{1,2})/(\\d{1,2})/', url)\n", + " if len(result) == 0:\n", + " return 'No date Found in \"{}\"'.format(url)\n", + " else: \n", + " return result\n", + " # pass\n", + "\n", + "url1= \"https://www.washingtonpost.com/news/football-insider/wp/2016/09/02/odell-beckhams-fame-rests-on-one-stupid-little-ball-josh-norman-tells-author/\"\n", + "print(extract_date(url1)) # [('2016', '09', '02')]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "gyD5AZW7os3z" + }, + "source": [ + "25) Write a Python program to convert a date of yyyy-mm-dd format to dd-mm-yyyy format." + ] + }, + { + "cell_type": "code", + "execution_count": 367, + "metadata": { + "id": "bo-jpYqZos30", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Original date in YYY-MM-DD Format: 2026-01-02\n", + "New date in DD-MM-YYYY Format: 02-01-2026\n" + ] + } + ], + "source": [ + "# Solution\n", + "def change_date_format(dt):\n", + " return re.sub(r'(\\d{4})-(\\d{1,2})-(\\d{1,2})', r'\\3-\\2-\\1', dt1) \n", + " #pass\n", + "\n", + "dt1 = \"2026-01-02\"\n", + "print(\"Original date in YYY-MM-DD Format: \",dt1) # Original date in YYY-MM-DD Format: 2026-01-02\n", + "print(\"New date in DD-MM-YYYY Format: \",change_date_format(dt1)) # New date in DD-MM-YYYY Format: 02-01-2026" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "IQ2SNL-gos30" + }, + "source": [ + "26) Write a Python program to match if any words from a list of words starting with letter 'P'." + ] + }, + { + "cell_type": "code", + "execution_count": 365, + "metadata": { + "id": "2hP4Twe0os31", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('Python', 'PHP')\n" + ] + } + ], + "source": [ + "# Sample strings.\n", + "def print_words_starting_with_P(words):\n", + " for string in words:\n", + " result = re.match(\"(P\\w+)\\W(P\\w+)\", string)\n", + " if result:\n", + " print(result.groups())\n", + " #pass\n", + "\n", + "words = [\"Python PHP\", \"Java JavaScript\", \"c c++\"]\n", + "print_words_starting_with_P(words) # ('Python', 'PHP')" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "MEUMKMn0os31" + }, + "source": [ + "27) Write a Python program to separate and print the numbers of a given string." + ] + }, + { + "cell_type": "code", + "execution_count": 364, + "metadata": { + "id": "xG8c9PtUos32", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "10\n", + "20\n", + "30\n" + ] + } + ], + "source": [ + "# Solution\n", + "def print_all_numbers(text):\n", + " result = re.split('\\D+', text)\n", + " for string in result:\n", + " print(string)\n", + " #pass\n", + "\n", + "# Sample string.\n", + "text = \"Ten 10, Twenty 20, Thirty 30\"\n", + "print_all_numbers(text)\n", + "# 10\n", + "# 20\n", + "# 30" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "krdKu3Mvos32" + }, + "source": [ + "28) Write a Python program to find all words starting with 'a' or 'e' in a given string." + ] + }, + { + "cell_type": "code", + "execution_count": 360, + "metadata": { + "id": "3hsR5278os32", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['example', 'eates', 'an', 'ayList', 'apacity', 'elements', 'elements', 'are', 'en', 'added', 'ayList', 'and', 'ayList', 'ed', 'accordingly']\n" + ] + } + ], + "source": [ + "# Solution\n", + "def get_all_words_containing_a_or_e(text):\n", + " return (re.findall (r'[ae]\\w+', text))\n", + " #pass\n", + "\n", + "\n", + "# Input.\n", + "text = \"The following example creates an ArrayList with a capacity of 50 elements. Four elements are then added to the ArrayList and the ArrayList is trimmed accordingly.\"\n", + "print(get_all_words_containing_a_or_e(text))\n", + "# ['example', 'eates', 'an', 'ayList', 'apacity', 'elements', 'elements', 'are', 'en', 'added', 'ayList', 'and', 'ayList', 'ed', 'accordingly']" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "CxfIZ5o9os33" + }, + "source": [ + "29) Write a Python program to separate and print the numbers and their position of a given string." + ] + }, + { + "cell_type": "code", + "execution_count": 359, + "metadata": { + "id": "XIuiRvmAos33", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "50\n", + "Index position: 62\n" + ] + } + ], + "source": [ + "# Solution\n", + "def print_all_numbers_and_their_position(text):\n", + " result = re.finditer(r'\\d+', text)\n", + " for string in result:\n", + " print(string.group(0))\n", + " print(\"Index position:\", string.start())\n", + " #pass\n", + " \n", + "\n", + "# Input.\n", + "text = \"The following example creates an ArrayList with a capacity of 50 elements. Four elements are then added to the ArrayList and the ArrayList is trimmed accordingly.\"\n", + "print_all_numbers_and_their_position(text)\n", + "# 50\n", + "# Index position: 62" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "JguO0fUjos34" + }, + "source": [ + "30) Write a Python program to abbreviate 'Road' as 'Rd.' in a given string." + ] + }, + { + "cell_type": "code", + "execution_count": 358, + "metadata": { + "id": "VJE1Xm2Bos34", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "21 Ramkrishna Rd.\n" + ] + } + ], + "source": [ + "# Solution\n", + "def abbreviate_road(street):\n", + " return re.sub(r'Road', 'Rd.', street)\n", + "\n", + "street = '21 Ramkrishna Road'\n", + "\n", + "print(abbreviate_road(street)) # 21 Ramkrishna Rd.\n" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.0" + }, + "vscode": { + "interpreter": { + "hash": "5238573367df39f7286bb46f9ff5f08f63a01a80960060ce41e3c79b190280fa" + } + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/student_json.py b/student_json.py new file mode 100644 index 0000000..a0a8e59 --- /dev/null +++ b/student_json.py @@ -0,0 +1,44 @@ +# Calculating the total, average and grade for the students in the student file and +# writing the result to the JSON file + +import json + +# Read the JSON data from the JSON file +with open('studentfile.json', "r") as file: + student = json.load(file) + +student_list = [] + +for item in student: + total = 0 + item1 = 0 + item1 = item["course"]["marks"] + + # Calculating the total marks + for mark, value in item1.items(): + total += value + + item["course"]["total"] = total + + # Calculating the average + item["course"]["average"] = total/len(item1) + + # Assigning the grade based on the range of the marks + if item["course"]["average"] > 75 and item["course"]["average"] < 100: + item["course"]["grade"] = "A" + elif item["course"]["average"] > 65 and item["course"]["average"] < 75: + item["course"]["grade"] = "B" + elif item["course"]["average"] > 45 and item["course"]["average"] < 65: + item["course"]["grade"] = "C" + else: + item["course"]["grade"] = "F" + + student_list.append(item) + +# Sorting the student list by the grade ascending +student_sorted = sorted(student_list, key = lambda x: x["course"]["grade"]) +print(student_sorted) + +# Writing the result to the studentresult.json file +with open("studentresult.json", "w") as file: + json.dump(student_sorted, file, indent = 4) diff --git a/studentfile.json b/studentfile.json new file mode 100644 index 0000000..4e86aef --- /dev/null +++ b/studentfile.json @@ -0,0 +1,149 @@ +[ + { + "id" : "101", + "name" : "Samu", + "age" : 36, + "course" : {"course_name" : "Computer Science", + "marks": + { "tamil" : 78, + "english" : 75, + "computer" : 85, + "science" : 90 + } }, + "address" : "95 Commons Dr", + "hobbies" : "sports" + }, + + { + "id" : "102", + "name" : "abc", + "age" : 31, + "course" : {"course_name" : "Computer Science", + "marks": + { "tamil" : 99, + "english" : 98, + "computer" : 99, + "science" : 70 + } }, + "address" : "90 Main Street", + "hobbies" : "painting" + }, + + { + "id" : "103", + "name" : "def", + "age" : 20, + "course" : {"course_name" : "Computer Science", + "marks": + { "tamil" : 68, + "english" : 55, + "computer" : 35, + "science" : 50 + } }, + "address" : "9519 Kirk Street ", + "hobbies" : "drawing" + }, + + { + "id" : "104", + "name" : "ghi", + "age" : 21, + "course" : {"course_name" : "Computer Science", + "marks": + { "tamil" : 48, + "english" : 85, + "computer" : 95, + "science" : 75 + } }, + "address" : "100 Plano Dr", + "hobbies" : "Origami" + }, + + { + "id" : "105", + "name" : "jkl", + "age" : 19, + "course" : {"course_name" : "Computer Science", + "marks": + { "tamil" : 58, + "english" : 73, + "computer" : 23, + "science" : 67 + } }, + "address" : "49 Simmons Dr", + "hobbies" : "Sewing" + }, + + { + "id" : "106", + "name" : "Deepesh", + "age" : 19, + "course" : {"course_name" : "Computer Science", + "marks": + { "tamil" : 99, + "english" : 98, + "computer" : 100, + "science" : 69 + } }, + "address" : "221 Commodo Blvd.", + "hobbies" : "sports" + }, + + { + "id" : "107", + "name" : "wesley", + "age" : 40, + "course" : {"course_name" : "Computer Science", + "marks": + { "tamil" : 48, + "english" : 95, + "computer" : 79, + "science" : 98 + } }, + "address" : "23 Miskin Dr", + "hobbies" : "swimming" + }, + + { + "id" : "108", + "name" : "Randy", + "age" : 28, + "course" : {"course_name" : "Computer Science", + "marks": + { "tamil" : 78, + "english" : 73, + "computer" : 65, + "science" : 76 + } }, + "address" : "15 Cosmo Blvd.", + "hobbies" : "drawing" + }, + + { + "id" : "109", + "name" : "Tom", + "age" : 20, + "course" : {"course_name" : "Computer Science", + "marks": + { "tamil" : 90, + "english" : 94, + "computer" : 92 + } }, + "address" : "39 Bridge Dr", + "hobbies" : "Sewing" + }, + + { + "id" : "110", + "name" : "Hercules", + "age" : 30, + "course" : {"course_name" : "Computer Science", + "marks": + { "tamil" : 59, + "english" : 82, + "computer" : 63 + } }, + "address" : "9526 Costco Street", + "hobbies" : "painting" + } +] diff --git a/studentresult.json b/studentresult.json new file mode 100644 index 0000000..52aba06 --- /dev/null +++ b/studentresult.json @@ -0,0 +1,190 @@ +[ + { + "id": "101", + "name": "Samu", + "age": 36, + "course": { + "course_name": "Computer Science", + "marks": { + "tamil": 78, + "english": 75, + "computer": 85, + "science": 90 + }, + "total": 328, + "average": 82.0, + "grade": "A" + }, + "address": "95 Commons Dr", + "hobbies": "sports" + }, + { + "id": "102", + "name": "abc", + "age": 31, + "course": { + "course_name": "Computer Science", + "marks": { + "tamil": 99, + "english": 98, + "computer": 99, + "science": 70 + }, + "total": 366, + "average": 91.5, + "grade": "A" + }, + "address": "90 Main Street", + "hobbies": "painting" + }, + { + "id": "104", + "name": "ghi", + "age": 21, + "course": { + "course_name": "Computer Science", + "marks": { + "tamil": 48, + "english": 85, + "computer": 95, + "science": 75 + }, + "total": 303, + "average": 75.75, + "grade": "A" + }, + "address": "100 Plano Dr", + "hobbies": "Origami" + }, + { + "id": "106", + "name": "Deepesh", + "age": 19, + "course": { + "course_name": "Computer Science", + "marks": { + "tamil": 99, + "english": 98, + "computer": 100, + "science": 69 + }, + "total": 366, + "average": 91.5, + "grade": "A" + }, + "address": "221 Commodo Blvd.", + "hobbies": "sports" + }, + { + "id": "107", + "name": "wesley", + "age": 40, + "course": { + "course_name": "Computer Science", + "marks": { + "tamil": 48, + "english": 95, + "computer": 79, + "science": 98 + }, + "total": 320, + "average": 80.0, + "grade": "A" + }, + "address": "23 Miskin Dr", + "hobbies": "swimming" + }, + { + "id": "109", + "name": "Tom", + "age": 20, + "course": { + "course_name": "Computer Science", + "marks": { + "tamil": 90, + "english": 94, + "computer": 92 + }, + "total": 276, + "average": 92.0, + "grade": "A" + }, + "address": "39 Bridge Dr", + "hobbies": "Sewing" + }, + { + "id": "108", + "name": "Randy", + "age": 28, + "course": { + "course_name": "Computer Science", + "marks": { + "tamil": 78, + "english": 73, + "computer": 65, + "science": 76 + }, + "total": 292, + "average": 73.0, + "grade": "B" + }, + "address": "15 Cosmo Blvd.", + "hobbies": "drawing" + }, + { + "id": "110", + "name": "Hercules", + "age": 30, + "course": { + "course_name": "Computer Science", + "marks": { + "tamil": 59, + "english": 82, + "computer": 63 + }, + "total": 204, + "average": 68.0, + "grade": "B" + }, + "address": "9526 Costco Street", + "hobbies": "painting" + }, + { + "id": "103", + "name": "def", + "age": 20, + "course": { + "course_name": "Computer Science", + "marks": { + "tamil": 68, + "english": 55, + "computer": 35, + "science": 50 + }, + "total": 208, + "average": 52.0, + "grade": "C" + }, + "address": "9519 Kirk Street ", + "hobbies": "drawing" + }, + { + "id": "105", + "name": "jkl", + "age": 19, + "course": { + "course_name": "Computer Science", + "marks": { + "tamil": 58, + "english": 73, + "computer": 23, + "science": 67 + }, + "total": 221, + "average": 55.25, + "grade": "C" + }, + "address": "49 Simmons Dr", + "hobbies": "Sewing" + } +] \ No newline at end of file diff --git a/user_json.py b/user_json.py new file mode 100644 index 0000000..7fde8e7 --- /dev/null +++ b/user_json.py @@ -0,0 +1,30 @@ +# Fetching the required details from the user JSON data file + +import json +import requests + +# Getting the requests from the URL +response = requests.get("https://jsonplaceholder.typicode.com/users") + +# Loading the JSON data +users = json.loads(response.text) +user3=[] +users_phonenumbers = {"id":None,"name":None,"phone":None} + +# Iterating for all the users in the file +for item in users: + users_phonenumbers={} + users_phonenumbers["id"]=item["id"] + users_phonenumbers["name"]=item["name"] + users_phonenumbers["phone"]=item["phone"] + + # Appending the list with the required information + user3.append(users_phonenumbers) + +# Sorting the list by name ascending +users_sorted = sorted(user3, key=lambda x: x['name'] ) +print(users_sorted) + +# Writing the result with the required information to the JSON file +with open("filtered_user_file.json", "w") as data_file: + json.dump(users_sorted, data_file, indent = 2) diff --git a/xml_practice.py b/xml_practice.py new file mode 100644 index 0000000..a89daf1 --- /dev/null +++ b/xml_practice.py @@ -0,0 +1,102 @@ +import xml.etree.ElementTree as ET + +tree= ET.parse('movies.xml') +root= tree.getroot() + +#print(tree) +#print(ET.tostring(root, encoding = 'utf8').decode('utf8')) +#print(root.tag) #giving us the name of the element tag +#print(root.attrib) #giving us the element attributes in a dictionary +################blank dicitonary means no attributes +#print(len(root)) ##how many children the element has +#print([elem.tag for elem in root.iter()]) #gives me a list of all the elements + +for rating in root.iter('rating'): + # print(rating.text) + pass + + +for rating_pg in root.findall("./genre/decade/movie/[rating='PG']"): + #print(rating_pg.attrib) + pass + +kkid= root.find("./genre/decade/movie[@title= 'THE KARATE KID']") +kkid.attrib['title']= "The Karate Kid" +#print(kkid.attrib) + + +# Creating a new genre under the root +anime_genre = ET.SubElement(root, 'genre') +#print(ET.tostring(root, encoding = 'utf8').decode('utf8')) +anime_genre.attrib['category']= 'Anime' +#print(ET.tostring(anime_genre, encoding = 'utf8').decode('utf8')) + + +# Adding the decade under the genre +add_decade = root.find("./genre[@category= 'Anime']") # We are saving the location of Action + # and passing it to the add variable + +new_dec= ET.SubElement(add_decade, 'decade') +new_dec.attrib['years']= '2000s' + + + +# Adding the movie under the decade +add_movie = root.find("./genre[@category='Anime']/decade[@years = '2000s']") +new_movie = ET.SubElement(add_movie, 'movie') +new_movie.attrib['favorite'] = 'True' +new_movie.attrib['title'] = 'Gladiator' + + +# Adding the sub-tag format DVD under the +movie_path = root.find("./genre[@category='Anime']/decade[@years = '2000s']/movie[@title = 'Gladiator']") +new_format = ET.SubElement(movie_path, 'format') +new_format.attrib['multiple'] = 'No' +new_format.text = 'DVD' + + +# Adding the sub-tag year 2000s under the movie +new_year = ET.SubElement(movie_path, 'year') +new_year.text = '2000s' + + +# Adding the sub-tag rating R under the movie +new_rating = ET.SubElement(movie_path, 'rating') +new_rating.text = 'R' + + +# Adding the sub-tag description under the movie +new_description = ET.SubElement(movie_path, 'description') +new_description.text = 'A former Roman General sets out to exact vengeance against the corrupt emperor who murdered his family and sent him into slavery.' + + +# Writing the changes to the file +# A new genre category 'Anime', decade year '2000s', movie title 'Gladiator' and it's corresponding child would be updated to the file +tree.write('movies.xml') + + +# Appending the movie title 'Batman Returns' to the Genre category 'Anime' +batman = root.find("./genre/decade/movie[@title= 'Batman Returns']") +decade_path = root.find("./genre[@category='Anime']/decade[@years= '2000s']") +decade_path.append(batman) + + +# Deleting the movie title 'Batman Returns' from the genre category 'Action' with the year '1990s' +dec1990= root.find("./genre[@category='Action']/decade[@years= '1990s']") +dec1990.remove(batman) +action_path = root.find("./genre[@category= 'Action']") # We are saving the location of Action + # and passing it to the add variable + + +# Viewing the changes in the element tree from the root +print(ET.tostring(root, encoding='utf8').decode('utf8')) + + +# Writing the changes to the file +# A new movie title 'Batman Returns' would be appended to the genre category 'Anime' and +# the movie title 'Batman Returns' would be deleted from the genre category 'Action' with the year '1990s' +tree.write('movies.xml') + + + +