In [1]:
%matplotlib inline
import pandas as pd
import seaborn as sbn
sbn.set()
In [2]:
weather = pd.read_csv('weather.csv', index_col=0, na_values=[-99,-9900])
weather.date = pd.to_datetime(weather.date)
weather.pre = weather.pre / 100
weather.index = weather.date
del weather['date']
In [66]:
totalsnow = weather.groupby(weather.index.year).sum().snow
(totalsnow / (weather.groupby(weather.index.year).sum().pre + totalsnow)).plot(kind='bar')
Out[66]:
In [61]:
weather[(weather.snow > 0) & (weather.index.month < 11) & (weather.index.month > 3)]
Out[61]:
In [62]:
weather[(weather.pre > 0) & (weather.index.month == 1)]
Out[62]:
In [58]:
weather.groupby(weather.index.year).mean().high.plot()+weather.groupby(weather.index.year).mean().low.plot()
In [3]:
sbn.violinplot(x=weather.index.year//10*10,y=(weather.high+weather.low)/2)
Out[3]:
In [4]:
weather.sort_index(inplace=True)
snowonground = []
inches = 0
for idx,row in weather.iterrows():
inches += row['snow']
if row.high > 32:
inches -= (row['high']-32)/4
if inches < 0:
inches = 0
weather.set_value(idx,'totalsnow',inches)
snowonground.append(inches)
weather.totalsnow = snowonground
In [5]:
%time
def accsnow(row):
accsnow.inches += row.snow
if row.high > 32 and accsnow.inches >= 0:
accsnow.inches -= (row.high-32)*.25
if accsnow.inches < 0:
accsnow.inches = 0
return accsnow.inches
accsnow.inches = 0
weather['totalsnow'] = weather.apply(accsnow,axis=1)
In [8]:
weather[(weather.index.month == 12) & (weather.index.day == 25)].totalsnow.plot(kind='bar')
Out[8]:
In [33]:
d = {'totalsnow':[]}
df = pd.DataFrame(data=d)
for yr in range(1893,2013):
df.loc[yr] = weather[weather.index.year==yr].snow.values.sum()
In [35]:
df.plot(kind='bar')
Out[35]:
In [ ]:
In [53]:
weather[(weather.index.dayofweek == 5) & (weather.index.month > 4) & (weather.index.month < 10)].groupby('week').mean().pre.plot('bar')
Out[53]:
In [68]:
def flood(row):
if row.pre > 0:
flood.days += 1
else:
flood.days = 0
return flood.days
flood.days = 0
weather['daysOfRain'] = weather.apply(flood,axis=1)
In [75]:
weather.sort('daysOfRain',ascending=False).daysOfRain.head()
Out[75]:
In [79]:
def drought(row):
if row.pre == 0.0:
drought.days += 1
else:
drought.days = 0
return drought.days
drought.days = 0
weather['daysOfDrought'] = weather.apply(drought,axis=1)
In [83]:
weather.sort('daysOfDrought',ascending=False).daysOfDrought.head()
Out[83]:
In [17]:
w = weather
w['tempdiff'] = (w.high - w.low)
In [19]:
w[w.tempdiff == w.tempdiff.max()]
Out[19]:
In [16]:
weather[weather.pre == weather.pre.max()]
Out[16]:
In [6]:
weather[weather.snow == weather.snow.max()]
Out[6]:
In [4]:
weather[weather.high == weather.high.max()]
Out[4]:
In [15]:
weather[weather.low == weather.low.min()]
Out[15]: