lab4

.pdf

School

University of Oregon *

*We aren’t endorsed by this school

Course

102

Subject

Geography

Date

Apr 27, 2024

Type

pdf

Pages

5

Uploaded by MajorKookaburaMaster1051 on coursehero.com

lab4 April 26, 2024 [1]: import numpy as np import pandas as pd import otter grader = otter . Notebook() 0.1 Lab 4: Keep going in pandas This lab is for more practice using pandas . Below are some functions you may find useful for these exercises. pd.Series.value_counts pd.DataFrame.groupby pd.crosstab pd.DataFrame.sort_values We will be summarizing and manipulating information coming from a history of weather conditions. [2]: weather = pd . read_csv( "weatherHistory.csv" ) weather . head() [2]: Formatted Date Summary Precip Type Temperature (C) \ 0 2006-04-01 00:00:00.000 +0200 Partly Cloudy rain 9.472222 1 2006-04-01 01:00:00.000 +0200 Partly Cloudy rain 9.355556 2 2006-04-01 02:00:00.000 +0200 Mostly Cloudy rain 9.377778 3 2006-04-01 03:00:00.000 +0200 Partly Cloudy rain 8.288889 4 2006-04-01 04:00:00.000 +0200 Mostly Cloudy rain 8.755556 Apparent Temperature (C) Humidity Wind Speed (km/h) \ 0 7.388889 0.89 14.1197 1 7.227778 0.86 14.2646 2 9.377778 0.89 3.9284 3 5.944444 0.83 14.1036 4 6.977778 0.83 11.0446 Wind Bearing (degrees) Visibility (km) Loud Cover Pressure (millibars) \ 1
0 251.0 15.8263 0.0 1015.13 1 259.0 15.8263 0.0 1015.63 2 204.0 14.9569 0.0 1015.94 3 269.0 15.8263 0.0 1016.41 4 259.0 15.8263 0.0 1016.51 Daily Summary 0 Partly cloudy throughout the day. 1 Partly cloudy throughout the day. 2 Partly cloudy throughout the day. 3 Partly cloudy throughout the day. 4 Partly cloudy throughout the day. Question 1 Subset the weather data for just the Summary , Temperature (C) and Humidity columns. [3]: weather_sub = weather[[ 'Summary' , 'Temperature (C)' , 'Humidity' ]] [4]: grader . check( "q1_1" ) [4]: q1_1 results: All test cases passed! Question 2 How many total days in the data were “Clear”? [7]: clear_days = weather[ 'Precip Type' ] == 'Clear' clear_days [7]: [0 False 1 False 2 False 3 False 4 False 96448 False 96449 False 96450 False 96451 False 96452 False Name: Precip Type, Length: 96453, dtype: bool] [8]: grader . check( "q1_2" ) [8]: q1_2 results: q1_2 - 1 result: ￿ Test case failed Trying: 5000 < clear_days < 15000 2
Expecting: True ********************************************************************** Line 1, in q1_2 0 Failed example: 5000 < clear_days < 15000 Exception raised: Traceback (most recent call last): File "/opt/conda/lib/python3.11/doctest.py", line 1351, in __run exec(compile(example.source, filename, "single", File "<doctest q1_2 0[0]>", line 1, in <module> 5000 < clear_days < 15000 TypeError: '<' not supported between instances of 'int' and 'list' q1_2 - 2 result: ￿ Test case failed Trying: clear_days == 10890 Expecting: True ********************************************************************** Line 1, in q1_2 1 Failed example: clear_days == 10890 Expected: True Got: False Question 3 Which 5 weather conditions (“Summary”) had the highest average temperature? Return the answer as a 5 element array. [ ]: ... hottest_conditions = ... hottest_conditions [ ]: grader . check( "q1_3" ) Question 4 Which 5 weather conditions (“Summary”) had the highest average humidity? Return the answer as a 5 element array. [ ]: humid_conditions = ... humid_conditions [ ]: grader . check( "q1_4" ) 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help