Question

In: Computer Science

python - needed asap (thank you in advance!!!!) Using the provided climate_data_Dec2017.csv file, find out how...

python - needed asap (thank you in advance!!!!)

Using the provided climate_data_Dec2017.csv file, find out how many readings there were across our recorded weather stations for each wind direction on the 26th of December. The file contains data for more than this particular day. To make sure that you only include readings from the 26th, you should use pandas to filter the data. If any wind direction value can still be found for the other days but not 26th, it should still appear in the result with value zero. While we encourage you not to rely on a loop for this part, you are free to do as you see fit. (Hint: pandas can help you find a set of unique values from a series of data) Let your program print out sorted wind directions in ascending alphabetical order.

The output should look like this:

E : 4
ENE : 2
ESE : 1
N : 0
NE : 1
NNE : 1
NNW : 1
NW : 0
S : 0
SE : 3
SSE : 3
SSW : 0
SW : 1
W : 0
WNW : 0
WSW : 0

data file

Date,State,City,Station Code,Minimum temperature (C),Maximum temperature (C),Rainfall (mm),Evaporation (mm),Sunshine (hours),Direction of maximum wind gust,Speed of maximum wind gust (km/h),9am Temperature (C),9am relative humidity (%),3pm Temperature (C),3pm relative humidity (%)
2017-12-25,VIC,Melbourne,086338,15.1,21.4,0,8.2,10.4,S,44,17.2,57,20.7,54
2017-12-25,VIC,Bendigo,081123,11.3,26.3,0,,,ESE,46,17.2,53,25.5,25
2017-12-25,QLD,Gold Coast,040764,22.3,35.7,0,,,SE,59,29.2,53,27.7,67
2017-12-25,SA,Adelaide,023034,13.9,29.5,0,10.8,12.4,SE,43,18.6,42,27.7,17
2017-12-25,QLD,Brisbane,040913,22.5,36.2,0,11.0,10.0,WSW,61,29.5,53,32.3,53
2017-12-25,QLD,Townsville,032040,24.8,32.5,0,,,NNE,41,29.1,55,31.1,48
2017-12-25,QLD,Cairns,031011,20.3,33.3,0,,,E,41,29.2,59,32.4,45
2017-12-25,NSW,Wollongong,068228,15.9,21.3,7.6,,,SSW,48,18.5,80,19.5,70
2017-12-25,NSW,Newcastle,061055,19.8,21.6,0.6,,,S,48,20.2,83,20.9,74
2017-12-25,VIC,Ballarat,089002,8.5,21.4,0,,,SSE,54,13.3,62,21.1,40
2017-12-25,QLD,Sunshine C,040861,20.2,31.5,0,,,NNE,43,28.9,62,28.8,61
2017-12-25,NSW,Canberra,070351,13.4,23.0,0,,,ESE,39,15.0,66,21.9,47
2017-12-25,NSW,Albury,072160,14.7,29.1,0,,,SSE,37,18.7,42,26.6,32
2017-12-25,QLD,Toowoomba,041529,19.5,32.0,0,,,E,61,24.4,68,31.2,39
2017-12-25,VIC,Geelong,087184,14.1,21.6,0,,,S,41,16.7,58,19.9,53
2017-12-25,NT,Darwin,014015,24.0,27.6,20.0,6.6,0.0,NNE,46,25.4,91,27.3,81
2017-12-25,WA,Perth,009021,19.7,33.1,0,11.0,13.3,SW,39,27.8,34,31.1,29
2017-12-26,VIC,Ballarat,089002,10.8,29.1,0,,,SE,56,17.3,59,27.1,30
2017-12-26,NSW,Canberra,070351,10.8,22.4,0,,,E,39,18.3,57,21.8,48
2017-12-26,QLD,Brisbane,040913,19.0,29.7,54.8,12.4,7.5,E,26,25.2,77,28.8,56
2017-12-26,NSW,Newcastle,061055,18.5,22.5,3.8,,,SE,43,21.1,76,21.7,79
2017-12-26,SA,Adelaide,023034,18.0,33.3,0,11.4,12.7,E,43,25.7,23,28.6,28
2017-12-26,QLD,Toowoomba,041529,16.4,28.4,0,,,E,74,23.9,65,22.7,79
2017-12-26,WA,Perth,009021,15.4,27.4,0,9.0,13.2,SW,41,22.3,59,25.7,45
2017-12-26,VIC,Bendigo,081123,12.8,31.3,0,,,SE,41,20.5,50,30.3,27
2017-12-26,QLD,Gold Coast,040764,20.4,27.9,11.6,,,SSE,52,24.7,87,25.8,81
2017-12-26,VIC,Geelong,087184,12.5,26.6,0,,,SSE,31,18.9,69,23.8,50
2017-12-26,VIC,Melbourne,086338,12.5,30.5,0,8.0,12.9,SSE,37,17.4,66,27.0,43
2017-12-26,QLD,Cairns,031011,22.0,33.0,0,,,ENE,33,29.2,61,31.1,56
2017-12-26,NSW,Wollongong,068228,17.8,24.1,0,,,ENE,41,21.3,59,23.9,55
2017-12-26,QLD,Sunshine C,040861,19.9,28.6,7.4,,,ESE,33,28.4,67,27.6,68
2017-12-26,QLD,Townsville,032040,23.4,32.4,0,,,NE,37,29.9,52,30.4,50
2017-12-26,NSW,Albury,072160,14.0,30.7,0,,,NNE,31,21.6,46,29.2,26
2017-12-26,NT,Darwin,014015,24.6,31.6,8.0,4.6,1.4,NNW,56,26.7,90,30.3,72
2017-12-27,WA,Perth,009021,14.5,26.5,0,11.8,12.3,SSW,54,21.4,49,25.5,34
2017-12-27,NSW,Wollongong,068228,18.8,25.1,0,,,NE,43,21.8,77,23.3,72
2017-12-27,VIC,Geelong,087184,14.9,37.2,0,,,N,41,26.4,46,35.9,20
2017-12-27,QLD,Sunshine C,040861,21.5,28.8,1.4,,,SE,33,26.5,73,27.6,66
2017-12-27,NSW,Albury,072160,15.0,32.5,0,,,E,30,23.6,54,30.9,29
2017-12-27,VIC,Ballarat,089002,15.3,32.9,0,,,N,56,22.2,55,30.9,30
2017-12-27,QLD,Toowoomba,041529,16.7,26.9,29.4,,,E,57,20.4,80,26.1,57
2017-12-27,QLD,Gold Coast,040764,20.3,29.4,0.2,,,S,41,26.4,72,27.5,71
2017-12-27,NSW,Canberra,070351,15.8,29.1,0,,,NE,33,18.9,68,26.4,37
2017-12-27,SA,Adelaide,023034,20.6,36.0,0,8.8,3.8,WSW,48,32.9,9,28.9,34
2017-12-27,VIC,Melbourne,086338,17.3,34.5,0,11.8,10.4,NW,46,25.3,45,32.9,32
2017-12-27,VIC,Bendigo,081123,16.3,35.6,0,,,N,46,22.7,54,32.9,30
2017-12-27,QLD,Cairns,031011,22.4,32.6,0,,,NE,35,29.1,59,31.3,55
2017-12-27,QLD,Townsville,032040,23.2,32.8,0,,,NE,37,30.3,52,30.0,59
2017-12-27,QLD,Brisbane,040913,20.7,29.6,3.0,5.6,10.0,E,30,27.3,60,28.2,56
2017-12-27,NSW,Newcastle,061055,20.5,23.5,0,,,E,39,22.1,80,22.9,79
2017-12-27,NT,Darwin,014015,23.5,31.3,8.8,3.0,0.0,NW,15,28.7,77,29.5,73
2017-12-28,NSW,Newcastle,061055,19.8,24.3,0,,,E,41,22.6,76,23.6,81
2017-12-28,QLD,Toowoomba,041529,16.6,27.9,0,,,E,43,21.3,73,27.4,52
2017-12-28,SA,Adelaide,023034,21.1,25.0,0,10.2,1.0,SSE,26,22.1,82,23.8,74
2017-12-28,QLD,Sunshine C,040861,20.4,28.8,24.0,,,E,31,26.0,69,27.6,63
2017-12-28,VIC,Ballarat,089002,20.1,30.4,0,,,NW,31,25.1,42,29.3,31
2017-12-28,NSW,Wollongong,068228,19.8,25.3,0,,,NE,39,23.2,73,23.8,75
2017-12-28,NSW,Canberra,070351,12.9,32.4,0,,,NW,37,20.1,70,32.4,31
2017-12-28,VIC,Bendigo,081123,22.6,34.4,0,,,NNE,24,26.2,43,32.6,29
2017-12-28,QLD,Townsville,032040,26.9,32.6,0,,,ENE,39,30.2,57,31.0,54
2017-12-28,WA,Perth,009021,15.7,28.8,0,11.2,13.2,SSW,52,22.1,44,25.6,40
2017-12-28,VIC,Melbourne,086338,24.0,32.8,0,14.0,4.1,SSW,31,26.4,46,23.9,73
2017-12-28,QLD,Brisbane,040913,20.6,29.4,0.6,7.8,12.5,ESE,24,27.5,60,28.8,57
2017-12-28,QLD,Gold Coast,040764,20.7,28.9,0,,,SSE,35,26.5,75,28.1,64
2017-12-28,NSW,Albury,072160,17.4,32.8,0,,,ENE,35,22.3,63,31.9,39
2017-12-28,VIC,Geelong,087184,22.9,28.0,0,,,S,39,25.7,54,20.7,85
2017-12-28,NT,Darwin,014015,25.6,34.5,1.0,0.8,9.8,WNW,31,31.0,72,33.1,62
2017-12-28,QLD,Cairns,031011,22.6,34.2,0,,,E,39,30.2,58,32.8,46
2017-12-29,NSW,Wollongong,068228,19.4,25.8,0,,,SW,22,22.7,85,23.2,84
2017-12-29,VIC,Bendigo,081123,20.6,30.6,0.8,,,SW,39,23.6,76,29.6,47
2017-12-29,NSW,Newcastle,061055,20.8,26.3,0,,,ENE,41,24.2,78,25.7,68
2017-12-29,SA,Adelaide,023034,18.2,22.7,2.4,2.8,1.9,WSW,33,20.3,70,21.5,64
2017-12-29,QLD,Toowoomba,041529,18.9,28.9,0,,,NNE,39,22.5,81,27.8,48
2017-12-29,NT,Darwin,014015,26.1,33.7,0,5.2,7.4,S,31,30.8,68,32.4,66
2017-12-29,VIC,Ballarat,089002,15.6,26.6,0,,,NNW,44,21.4,83,18.9,99
2017-12-29,QLD,Townsville,032040,26.0,33.2,0,,,NE,35,30.8,55,31.5,49
2017-12-29,NSW,Canberra,070351,18.3,33.4,0,,,NW,46,24.7,56,31.3,33
2017-12-29,QLD,Cairns,031011,24.9,34.3,0,,,E,39,29.8,61,32.6,47
2017-12-29,WA,Perth,009021,15.6,30.0,0,8.8,13.1,WSW,41,22.9,43,27.5,38
2017-12-29,VIC,Melbourne,086338,18.6,24.4,0.2,5.8,1.0,SSW,35,19.5,78,20.0,85
2017-12-29,QLD,Gold Coast,040764,22.4,28.8,10.2,,,NNE,26,26.0,91,27.3,74
2017-12-29,NSW,Albury,072160,21.0,27.3,1.4,,,SSE,33,23.0,82,25.9,66
2017-12-29,VIC,Geelong,087184,17.2,22.6,0,,,SSW,26,19.3,79,18.7,93
2017-12-29,QLD,Sunshine C,040861,21.9,29.9,0,,,NE,26,27.5,65,28.5,62
2017-12-30,NSW,Wollongong,068228,21.6,29.7,0.6,,,SE,46,25.2,73,26.8,69
2017-12-30,QLD,Townsville,032040,25.8,33.6,0.2,,,N,35,30.2,60,31.7,49
2017-12-30,QLD,Brisbane,040913,23.3,32.2,0,8.6,7.8,NE,24,28.9,55,30.4,65
2017-12-30,VIC,Melbourne,086338,15.6,21.3,8.4,4.2,8.1,SSW,65,19.0,60,19.6,71
2017-12-30,VIC,Bendigo,081123,13.6,25.3,0.4,,,SW,43,17.8,60,22.2,47
2017-12-30,QLD,Cairns,031011,22.0,33.9,0,,,ENE,46,29.0,61,31.2,62
2017-12-30,QLD,Sunshine C,040861,21.0,31.3,0,,,NNE,43,29.0,54,28.1,72
2017-12-30,VIC,Geelong,087184,13.6,22.8,4.6,,,W,56,17.9,78,21.9,41
2017-12-30,NSW,Canberra,070351,18.6,28.3,16.4,,,WNW,50,22.8,70,27.8,33
2017-12-30,QLD,Gold Coast,040764,23.4,31.5,0,,,NW,41,27.2,61,28.0,74
2017-12-30,NSW,Albury,072160,20.3,27.7,13.8,,,W,44,23.0,65,26.2,36
2017-12-30,VIC,Ballarat,089002,8.2,18.6,1.4,,,WSW,50,14.7,81,16.6,70
2017-12-30,SA,Adelaide,023034,17.4,22.7,0.2,4.8,10.2,SW,41,19.1,72,22.0,51
2017-12-30,NT,Darwin,014015,24.2,34.8,1.2,4.4,11.2,NW,28,29.9,71,33.6,61
2017-12-30,NSW,Newcastle,061055,23.2,34.1,2.0,,,NW,52,24.6,81,31.2,50
2017-12-30,QLD,Toowoomba,041529,19.1,30.2,0,,,N,31,23.6,70,30.2,49
2017-12-31,QLD,Toowoomba,041529,21.1,30.2,1.4,,,E,54,24.7,75,23.6,66
2017-12-31,NSW,Canberra,070351,14.9,27.9,0,,,NNW,37,19.7,65,26.2,37
2017-12-31,VIC,Bendigo,081123,8.9,29.0,0,,,WNW,33,17.3,54,26.7,28
2017-12-31,NSW,Newcastle,061055,21.3,25.3,0.2,,,SSE,46,22.5,78,22.4,82
2017-12-31,NSW,Wollongong,068228,18.9,23.4,19.6,,,NNE,48,19.2,93,21.1,84
2017-12-31,QLD,Sunshine C,040861,24.1,32.5,0,,,SSW,65,30.3,62,27.1,78
2017-12-31,QLD,Gold Coast,040764,22.4,29.1,14.8,,,SE,56,27.1,84,25.6,97
2017-12-31,VIC,Geelong,087184,9.8,25.9,0,,,SSE,33,16.4,70,23.9,48
2017-12-31,QLD,Brisbane,040913,24.7,33.6,0,8.0,6.6,E,31,30.0,63,27.1,76
2017-12-31,VIC,Melbourne,086338,12.0,25.7,0.2,4.0,13.5,S,33,17.3,60,22.5,48
2017-12-31,WA,Perth,009021,19.7,33.6,0,12.4,13.2,WSW,41,26.0,45,30.6,36
2017-12-31,VIC,Ballarat,089002,5.7,25.2,2.0,,,W,39,12.8,77,23.5,35
2017-12-31,QLD,Townsville,032040,26.7,33.3,0,,,NNE,33,30.8,55,33.0,44
2017-12-31,NT,Darwin,014015,27.4,34.1,0,6.0,8.6,N,26,30.8,73,32.8,59
2017-12-31,QLD,Cairns,031011,21.6,33.1,0,,,NNE,28,29.9,61,31.2,54
2017-12-31,NSW,Albury,072160,12.7,29.5,0,,,WNW,33,19.9,67,27.7,30
2017-12-31,SA,Adelaide,023034,13.7,22.3,0,8.0,9.7,SW,35,17.7,59,21.4,53

Solutions

Expert Solution

Given above is the image of the python code required to complete the above task. I am also copying the code here. In case of compilation errors on copying the below code due to stray characters, please refer to the image above .

# Load the Pandas libraries with alias 'pd'
import pandas as pd
# Read data from file ' climate_data_Dec2017.csv'
# (should be in the same directory that your program resides in)
data = pd.read_csv("climate_data_Dec2017.csv")
# Preview of data frame
data.head()
direction_freq = data[data['Date'] == '2017-12-26']['Direction of maximum wind gust'].value_counts().reindex(data['Direction of maximum wind gust'].unique(), fill_value = 0)
direction_freq = direction_freq.sort_index(0).to_string()
print(direction_freq)

Explanation:

1. pandas had been imported under the alias name 'pd'.

2. read_csv() reads a comma separated values file and converts it into a pandas data frame using ', ' (comma) delimiter.

3. Ensure that the file climate_data_Dec2017.csv is in the same working directory as in your program.

3. direction_freq holds the answer to our problem, We filter all the rows with date '2017-12-26', because all values are for year 2017 and we need only dates for 26th December. We do value_counts() of those direction values, so it returns the frequency of directions only for 26th of December. But directions which are not present for that date will not appear yet. We need their count to be zero, so we reindex() the data from the previous index we created, grab all the unique values of direction, but this time all the directions will have the value 0 (fill_value = 0) whose value were NaN (Not a Number) earlier because they were not present.

4. Now, we sort the index based on the name of direction which is the first column, convert the index to string and print.


Related Solutions

how to find all the neighbors in a n-dimensional array in python? thank you in advance...
how to find all the neighbors in a n-dimensional array in python? thank you in advance all the neighboors of a coordinate*
USING PYTHON. Thank you in advance Write a program that allows the user to enter a...
USING PYTHON. Thank you in advance Write a program that allows the user to enter a series of string values into a list. When the user enters the string ‘done’, stop prompting for values. Once the user is done entering strings, create a new list containing a palindrome by combining the original list with the content of the original list in a reversed order. Sample interaction: Enter string: My Enter string: name Enter string: is Enter string: Sue Enter string:...
Using Python read dataset in the HTML in beautiful way. You need to read CSV file...
Using Python read dataset in the HTML in beautiful way. You need to read CSV file ( Use any for example, You can use small dataset) You need to use pandas library You need to use Flask Make search table like YouTube has.
how to read a csv file in php not using fgetscsv or fgets. Just using file("Stores.csv");...
how to read a csv file in php not using fgetscsv or fgets. Just using file("Stores.csv"); or fopen("Stores.csv", "r"); and making into a html table? It print but it keeps saying Notice: Undefined offset: , Notice: Undefined offset: 2, etc at the top. Acme,Walmart,Ross,BJs,Target,Marshalls,Foot Locker,Giant,Charming Charlie 142,160,28,10,5,3,60,0.28,3167 175,180,18,8,4,1,12,0.43,4033 129,132,13,6,3,1,41,0.33,1471 138,140,17,7,3,1,22,0.46,3204 232,240,25,8,4,3,5,2.05,3613 135,140,18,7,4,3,9,0.57,3028 150,160,20,8,4,3,18,4.00,3131 207,225,22,8,4,2,16,2.22,5158 271,285,30,10,5,2,30,0.53,5702 89,90,10,5,3,1,43,0.30,2054 153,157,22,8,3,3,18,0.38,4127 87,90,16,7,3,1,50,0.65,1445 234,238,25,8,4,2,2,1.61,2087 106,116,20,8,4,1,13,0.22,2818 175,180,22,8,4,2,15,2.06,3917 165,170,17,8,4,2,33,0.46,2220 166,170,23,9,4,2,37,0.27,3498 136,140,19,7,3,1,22,0.63,3607 148,160,17,7,3,2,13,0.36,3648 151,153,19,8,4,2,24,0.34,3561 180,190,24,9,4,2,10,1.55,4681 293,305,26,8,4,3,6,0.46,7088 167,170,20,9,4,2,46,0.46,3482 190,193,22,9,5,2,37,0.48,3920 184,190,21,9,5,2,27,1.30,4162 157,165,20,8,4,2,7,0.30,3785 110,115,16,8,4,1,26,0.29,3103 135,145,18,7,4,1,35,0.43,3363 567,625,64,11,4,4,4,0.85,12192 180,185,20,8,4,2,11,1.00,3831 183,188,17,7,3,2,16,3.00,3564 185,193,20,9,3,2,56,6.49,3765 152,155,17,8,4,1,33,0.70,3361 148,153,13,6,3,2,22,0.39,3950...
Problem 9 - PYTHON There is a CSV-formatted file called olympics2.csv. Write code that creates a...
Problem 9 - PYTHON There is a CSV-formatted file called olympics2.csv. Write code that creates a dictionary named country_olympians where the keys are country names and the values are lists of unique olympians from that country (no olympian's name should appear more than once for a given country). Name,Sex,Age,Team,Event,Medal A Dijiang,M,24,China,Basketball,NA A Lamusi,M,23,China,Judo,NA Gunnar Nielsen Aaby,M,24,Denmark,Football,NA Edgar Lindenau Aabye,M,34,Sweden,Tug-Of-War,Gold Christine Jacoba Aaftink,F,21,Netherlands,Speed Skating,NA Christine Jacoba Aaftink,F,21,Netherlands,Speed Skating,NA Christine Jacoba Aaftink,F,25,Netherlands,Speed Skating,NA Christine Jacoba Aaftink,F,25,Netherlands,Speed Skating,NA Christine Jacoba Aaftink,F,27,Netherlands,Speed Skating,NA Christine...
{PYTHON }You have a CSV file containing the location and population of various cities around the...
{PYTHON }You have a CSV file containing the location and population of various cities around the world. For this question you'll be given a list of cities and return the total population across all those cities. Write a function named "total_population" that takes a string then a list as parameters where the string represents the name of a CSV file containing city data in the format "CountryCode,CityName,Region,Population,Latitude,Longitude" and the second parameter is a list where each element is itself a...
{PYTHON }You have a CSV file containing the location and population of various cities around the...
{PYTHON }You have a CSV file containing the location and population of various cities around the world. For this question you'll be given a list of cities and return the total population across all those cities. Write a function named "total_population" that takes a string then a list as parameters where the string represents the name of a CSV file containing city data in the format "CountryCode,CityName,Region,Population,Latitude,Longitude" and the second parameter is a list where each element is itself a...
build a python program that will be performing: - Read a CSV file 'annual.csv' enterprise into...
build a python program that will be performing: - Read a CSV file 'annual.csv' enterprise into a data structure - Count the number of rows and columns - Determine if the data contains empty values - Replace the empty values by 'NA' for strings, '0' for decimals and '0.0' for floats - Transform all Upper case characters to Lower case characters - Transform all Lower case characters to Upper case characters - save back the 'repaired' array as csv -...
Goal: to write a Python program that will read a playlist from a CSV file and...
Goal: to write a Python program that will read a playlist from a CSV file and display it in the console in the form of a table. https://s3.eu-west-2.amazonaws.com/bb-python-modules/Coursework/CW3/playlist_text_question.html The following is a link to the question. It includes all instruction and a template file (with additional instructions) where the answer must be completed.
How would I create a nested dictionary given a csv file in Python? Say I want...
How would I create a nested dictionary given a csv file in Python? Say I want to make a dictionary that read {'country':{'China':'Fit', 'China':'Overweight', 'USA': 'Overweight', 'USA': 'Fit', 'England':'Fit'...}, 'category':{'Asian':'Fit', 'Caucasian': 'Overweight', 'Caucasian':'Overweight', 'Asian': 'Fit', 'Middle Eastern': 'Fit'...}} given a file that had country category Weight China Asian Fit China Caucasian Overweight USA Caucasian Overweight USA Asian Fit England Middle Eastern Fit... ... And so on in the file.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT