-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDS101-02-avg_min_temperature-extended.py
36 lines (27 loc) · 1.26 KB
/
DS101-02-avg_min_temperature-extended.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pandas
import pandasql
def avg_min_temperature(filename):
"""
This function should run a SQL query on a dataframe of
weather data. More specifically you want to find the average
minimum temperature on rainy days where the minimum temperature
is greater than 55 degrees.
You might also find that interpreting numbers as integers or floats may not
work initially. In order to get around this issue, it may be useful to cast
these numbers as integers. This can be done by writing cast(column as integer).
So for example, if we wanted to cast the maxtempi column as an integer, we would actually
write something like where cast(maxtempi as integer) = 76, as opposed to simply
where maxtempi = 76.
You can see the weather data that we are passing in below:
https://www.dropbox.com/s/7sf0yqc9ykpq3w8/weather_underground.csv
"""
weather_data = pandas.read_csv(filename)
q = """
select avg(cast (mintempi as integer))
from weather_data
where rain = 1 and cast (mintempi as integer) > 55
"""
# Execute your SQL command against the pandas frame
mean_temp_weekends = pandasql.sqldf(q.lower(), locals())
return mean_temp_weekends
print avg_min_temperature(u'Data\weather_underground.csv')