-
Notifications
You must be signed in to change notification settings - Fork 0
/
features.py
25 lines (20 loc) · 995 Bytes
/
features.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
# Gather some features
def build_sales_features(features, data):
# Use some properties directly
features.extend(['Store'])
features.append('SchoolHoliday')
data['SchoolHoliday'] = data['SchoolHoliday'].astype(float)
for x in ['a', 'b', 'c']:
features.append('StateHoliday_' + x)
data['StateHoliday_' + x] = data['StateHoliday'].map(lambda y: 1 if y == x else 0)
features.append('DayOfWeek')
features.append('month')
features.append('day')
features.append('year')
data['year'] = data.Date.apply(lambda x: x.split('-')[0])
data['year'] = data['year'].astype(float)
data['month'] = data.Date.apply(lambda x: x.split('-')[1])
data['month'] = data['month'].astype(float)
data['day'] = data.Date.apply(lambda x: x.split('-')[2])
data['day'] = data['day'].astype(float)
data['datetime'] = data.Date.apply(lambda x: dt.datetime(int(x.split('-')[0]),int(x.split('-')[1]),int(x.split('-')[2]),23,59,59))