-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
88 lines (73 loc) · 2.61 KB
/
utils.py
File metadata and controls
88 lines (73 loc) · 2.61 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'''
Utilidades que hice para manejar los DataFrame mientras aprendía pandas.
'''
#import matplotlib.pyplot as plt
import pandas as pd
from datetime import datetime
meses=['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre']
inv_range = [5,6,7,8]
ver_range = [11, 12, 1, 2, 3]
def month_name(month):
return meses[month-1]
def month_number(month):
return meses.index(month)+1
def df_invierno(df, i_year, f_year):
invierno = pd.DataFrame()
for year in range(i_year, f_year+1):
i = datetime(year, 5, 1, 0, 0)
f = datetime(year, 8, 31, 23, 0)
frame = [invierno,df.loc[i:f]]
invierno = pd.concat(frame)
return invierno
def gpr_invierno(date):
return date.year
def df_verano(df, i_year, f_year):
verano = pd.DataFrame()
for year in range(i_year, f_year+1):
i = datetime(year, 11, 1, 0, 0)
f = datetime(year+1, 3, 31, 23, 0)
frame = [verano,df.loc[i:f]]
verano = pd.concat(frame)
return verano
def gpr_verano(date):
if date.month >= 11:
return date.year
else:
return date.year-1
def o3delta(df, delta):
if delta == 0:
return df
df = df.reset_index()
dfr = df['O3']
dfl = df.drop(columns='O3')
dfr = dfr.iloc[delta:].reset_index(drop=True)
dfl = dfl.iloc[:-delta].reset_index(drop=True)
df = pd.concat([dfl, dfr], axis=1)
df.set_index('registered_on')
return df
#def gpr_month(date):
# return month_name(date.month)
#def gpr_year_month(date):
# year = str(date.year)
# month = month_name(date.month)
# return year+" "+month
#def boxplot_by_month(gpi):
# gg = gpi.get_group(2010)[['NO']]
# gg['month'] = gg.index.to_frame().agg(lambda x:x.index.month)
# hh = pd.DataFrame()
# hh = pd.concat([hh.reset_index().drop('index', axis=1), gg[gg['month']==5].reset_index()['NO']], ignore_index=True, axis=1)
# hh.describe()
# hh = pd.concat([hh.reset_index().drop('index', axis=1), gg[gg['month']==6].reset_index()['NO']], ignore_index=True, axis=1)
# #hh.describe()
# hh = pd.concat([hh.reset_index().drop('index', axis=1), gg[gg['month']==7].reset_index()['NO']], ignore_index=True, axis=1)
# hh = pd.concat([hh.reset_index().drop('index', axis=1), gg[gg['month']==8].reset_index()['NO']], ignore_index=True, axis=1)
#
# hh.columns = [5,6,7,8]
# #hh
# hh.iplot(kind='box', boxpoints = 'outliers' )
#
#def boxplot_all(df, predictor):
# df = df[[predictor]]
# group = df.groupby(by=gpr_year_month, sort=False)
# group.boxplot(subplots=False, figsize=(100,2))
# plt.show()