In [1]:
import numpy as np
import pandas as pd
import tensorflow as tf

In [2]:
user_name = 'David Mendoza'

In [3]:
df = pd.read_csv('transaction.csv')
df


Out[3]:
time name gender age company name company label amount
0 2017-07-02 22:27:48 Rachel Trujillo male 36 Coursera Inc. Education 111.22
1 2017-06-10 12:37:05 Rachel Trujillo male 36 Laura Mercier Cosmetics. Beauty 108.46
2 2017-06-07 14:24:02 Rachel Trujillo male 36 Synovus Financial Corp. Investment 208.21
3 2017-06-25 15:36:22 Rachel Trujillo male 36 Peak Tramways Company Limited Transport 222.79
4 2017-06-30 03:34:48 Rachel Trujillo male 36 McDonald' s Dining 86.28
5 2017-06-29 18:00:00 Rachel Trujillo male 36 Pearson plc Education 47.68
6 2017-06-30 21:34:26 Rachel Trujillo male 36 Wal-Mart Stores Inc Grocery 93.69
7 2017-07-04 11:57:56 Rachel Trujillo male 36 Principal Financial Group Inc Investment 115.46
8 2017-06-13 06:54:58 Rachel Trujillo male 36 Voya Financial, Inc. Investment 142.11
9 2017-07-02 18:23:56 Rachel Trujillo male 36 The Dairy Farm Company, Limited Grocery 61.87
10 2017-06-17 03:32:26 Rachel Trujillo male 36 2U, Inc. Education 280.35
11 2017-07-03 13:44:19 Rachel Trujillo male 36 City Super Limited Grocery 281.82
12 2017-06-16 16:16:17 Rachel Trujillo male 36 GAP Clothing 9.13
13 2017-06-17 01:17:02 Rachel Trujillo male 36 Subway Dining 104.77
14 2017-06-21 11:14:37 Rachel Trujillo male 36 KOKUYO Co.,Ltd. Stationery 300.88
15 2017-06-11 21:15:08 Rachel Trujillo male 36 Raymond James Financial, Inc. Investment 33.22
16 2017-06-14 11:45:03 Rachel Trujillo male 36 KOKUYO Co.,Ltd. Stationery 297.04
17 2017-07-03 21:29:17 Rachel Trujillo male 36 Liberty Stationery Corp. Stationery 133.08
18 2017-06-20 09:04:47 Rachel Trujillo male 36 Ikari Area Entertainment 9.43
19 2017-06-10 18:31:22 Rachel Trujillo male 36 The 'Star' Ferry Company, Limited Transport 201.96
20 2017-07-05 20:58:23 Rachel Trujillo male 36 Tim Ho Wan Dining 292.67
21 2017-06-23 20:15:43 Rachel Trujillo male 36 BB Liquidating Inc Media 163.39
22 2017-06-24 15:32:14 Rachel Trujillo male 36 Parker Pen Company Stationery 260.15
23 2017-06-24 04:00:43 Rachel Trujillo male 36 Le.com Media 149.06
24 2017-07-04 03:13:19 Rachel Trujillo male 36 J. Crew Clothing 273.85
25 2017-06-12 00:30:44 Rachel Trujillo male 36 Voya Financial, Inc. Investment 93.04
26 2017-06-20 09:50:33 Rachel Trujillo male 36 Neway Karaoke Box Limited Entertainment 239.05
27 2017-06-22 22:08:41 Rachel Trujillo male 36 TCF Financial Corporation Investment 244.24
28 2017-06-11 13:26:35 Rachel Trujillo male 36 Principal Financial Group Inc Investment 117.48
29 2017-07-04 09:40:59 Rachel Trujillo male 36 Laura Mercier Cosmetics. Beauty 134.45
... ... ... ... ... ... ... ...
399970 2017-06-12 23:41:20 Kelsey Jones male 50 Sumitomo Mitsui Financial Group Inc Investment 16.89
399971 2017-06-29 22:55:52 Kelsey Jones male 50 Udacity, Inc. Education 197.18
399972 2017-06-08 21:36:12 Kelsey Jones male 50 Staedtler Mars GmbH & Co. KG Stationery 81.63
399973 2017-06-07 07:32:09 Kelsey Jones male 50 Waddell & Reed Financial, Inc. Investment 258.03
399974 2017-06-30 10:49:34 Kelsey Jones male 50 Shenzhen Comix Stationery Co., Ltd. Stationery 200.22
399975 2017-06-29 10:25:22 Kelsey Jones male 50 Hong Kong Dragon Airlines Ltd Transport 16.32
399976 2017-07-02 23:05:33 Kelsey Jones male 50 Maxim' s Catering Dining 265.12
399977 2017-06-14 09:14:25 Kelsey Jones male 50 Shinhan Financial Group Co Ltd Investment 113.96
399978 2017-06-16 23:01:34 Kelsey Jones male 50 The Kowloon Motor Bus Company Limited Transport 51.15
399979 2017-06-30 20:05:53 Kelsey Jones male 50 Xbox Entertainment 233.69
399980 2017-06-14 11:43:47 Kelsey Jones male 50 J. Crew Clothing 141.99
399981 2017-06-07 09:19:46 Kelsey Jones male 50 New World First Bus Services Limited Transport 197.35
399982 2017-06-28 11:42:38 Kelsey Jones male 50 edX Inc. Education 294.94
399983 2017-06-13 14:28:37 Kelsey Jones male 50 Yadkin Financial Corporation Investment 52.28
399984 2017-06-17 13:29:12 Kelsey Jones male 50 Netflix, Inc. Media 31.73
399985 2017-06-15 06:16:08 Kelsey Jones male 50 Ikari Area Entertainment 201.77
399986 2017-06-23 18:05:50 Kelsey Jones male 50 Levi Strauss & Co. Clothing 272.93
399987 2017-06-16 12:47:34 Kelsey Jones male 50 Spotify AB Media 114.97
399988 2017-06-22 20:57:56 Kelsey Jones male 50 Cathay Pacific Airways Transport 71.12
399989 2017-06-26 04:56:07 Kelsey Jones male 50 Coursera Inc. Education 275.30
399990 2017-07-02 17:11:21 Kelsey Jones male 50 Code School LLC. Education 92.36
399991 2017-06-16 02:28:35 Kelsey Jones male 50 Ryze Ultimate Trampoline Park Hong Kong Entertainment 283.62
399992 2017-07-04 20:10:37 Kelsey Jones male 50 Redbox Automated Retail, LLC. Media 169.40
399993 2017-06-17 02:49:32 Kelsey Jones male 50 McDonald' s Dining 55.72
399994 2017-06-28 08:49:46 Kelsey Jones male 50 Long Win Bus Company Limited Transport 156.04
399995 2017-07-02 21:33:10 Kelsey Jones male 50 New Oriental Education & Tech Grp Education 39.57
399996 2017-06-26 10:09:42 Kelsey Jones male 50 Xbox Entertainment 222.35
399997 2017-06-13 04:40:07 Kelsey Jones male 50 Tim Ho Wan Dining 163.53
399998 2017-06-13 16:58:51 Kelsey Jones male 50 G2000 Clothing 16.58
399999 2017-07-05 07:28:44 Kelsey Jones male 50 FANCL International, Inc. Beauty 211.63

400000 rows × 7 columns


In [9]:
user_age = list(df.loc[df['name'] == user_name, 'age'])[0]


Out[9]:
40

In [16]:
#generate same age dataframe
dfSameAge = df.loc[(df['age'] < 50 )]
dfSameAge = dfSameAge.loc[dfSameAge['age'] >= 40]
dfSameAge


Out[16]:
time name gender age company name company label amount
240 2017-06-24 12:16:21 Antonio Matthews male 46 Ryze Ultimate Trampoline Park Hong Kong Entertainment 294.16
241 2017-06-27 06:14:21 Antonio Matthews male 46 The Ohio & Michigan Paper Company Stationery 22.43
242 2017-06-23 00:00:28 Antonio Matthews male 46 Crackle, Inc. Media 23.09
243 2017-06-28 02:49:37 Antonio Matthews male 46 Shinhan Financial Group Co Ltd Investment 10.78
244 2017-06-29 00:07:48 Antonio Matthews male 46 Raymond James Financial, Inc. Investment 34.46
245 2017-06-30 14:37:31 Antonio Matthews male 46 Colourmix Cosmetics Company Limited Beauty 260.20
246 2017-07-04 14:19:29 Antonio Matthews male 46 PILOT CORPORATION Stationery 279.09
247 2017-06-19 23:04:54 Antonio Matthews male 46 Xbox Entertainment 22.47
248 2017-06-26 10:24:27 Antonio Matthews male 46 Hong Kong Tramways, Limited Transport 140.54
249 2017-06-19 00:38:13 Antonio Matthews male 46 The Kowloon Motor Bus Company Limited Transport 216.32
250 2017-06-18 10:45:22 Antonio Matthews male 46 Tesco PLC Grocery 196.59
251 2017-06-17 13:00:24 Antonio Matthews male 46 Pizza Hut Dining 264.03
252 2017-06-07 19:21:24 Antonio Matthews male 46 Coursera Inc. Education 150.28
253 2017-06-21 14:18:09 Antonio Matthews male 46 The PNC Financial Services Group, Inc. Investment 53.49
254 2017-06-14 10:15:00 Antonio Matthews male 46 VR Arena Entertainment 201.49
255 2017-07-01 21:29:14 Antonio Matthews male 46 Tim Ho Wan Dining 280.37
256 2017-06-21 07:26:54 Antonio Matthews male 46 Stifel Financial Corporation Investment 186.27
257 2017-06-18 21:44:55 Antonio Matthews male 46 Walt Disney Company Entertainment 150.97
258 2017-06-30 07:59:10 Antonio Matthews male 46 Sa Sa Cosmetic Co. Ltd. Beauty 106.11
259 2017-06-26 15:40:34 Antonio Matthews male 46 Youku Tudou Inc. Media 95.07
260 2017-06-11 07:46:14 Antonio Matthews male 46 Hok Yee Stationery Company Stationery 201.10
261 2017-06-13 13:15:08 Antonio Matthews male 46 Spotify AB Media 166.91
262 2017-06-07 05:15:56 Antonio Matthews male 46 Holister Co. Clothing 292.70
263 2017-07-03 03:41:33 Antonio Matthews male 46 AMC Entertainment Inc Entertainment 90.75
264 2017-06-29 17:30:13 Antonio Matthews male 46 Chegg Inc Education 254.66
265 2017-06-30 21:12:05 Antonio Matthews male 46 KKBOX Media 254.27
266 2017-06-26 16:52:54 Antonio Matthews male 46 Netflix, Inc. Media 260.99
267 2017-06-23 22:40:15 Antonio Matthews male 46 Tesco PLC Grocery 158.15
268 2017-07-03 15:44:55 Antonio Matthews male 46 Peak Tramways Company Limited Transport 248.20
269 2017-06-14 00:34:19 Antonio Matthews male 46 Tarena International, Inc. Education 63.47
... ... ... ... ... ... ... ...
399370 2017-06-12 12:41:42 Shelly Lawrence male 42 Code School LLC. Education 39.61
399371 2017-06-16 08:03:36 Shelly Lawrence male 42 Spotify AB Media 182.34
399372 2017-06-28 12:37:43 Shelly Lawrence male 42 Levi Strauss & Co. Clothing 159.57
399373 2017-06-21 13:48:31 Shelly Lawrence male 42 Udemy, Inc. Education 124.34
399374 2017-06-21 01:34:28 Shelly Lawrence male 42 The Kowloon Motor Bus Company Limited Transport 116.58
399375 2017-06-21 23:43:20 Shelly Lawrence male 42 Clinique Laboratories, llc. Beauty 217.69
399376 2017-06-11 15:57:07 Shelly Lawrence male 42 The Ohio & Michigan Paper Company Stationery 107.99
399377 2017-07-05 16:05:00 Shelly Lawrence male 42 L'Oreal SA Beauty 31.99
399378 2017-06-14 10:39:15 Shelly Lawrence male 42 AMC Entertainment Inc Entertainment 167.48
399379 2017-06-14 11:51:58 Shelly Lawrence male 42 Broadway Cinematheque Entertainment 119.18
399380 2017-06-20 08:27:30 Shelly Lawrence male 42 Stifel Financial Corporation Investment 215.80
399381 2017-07-03 16:12:08 Shelly Lawrence male 42 G2000 Clothing 249.15
399382 2017-06-23 04:26:36 Shelly Lawrence male 42 The Kowloon Motor Bus Company Limited Transport 81.81
399383 2017-06-19 18:24:20 Shelly Lawrence male 42 Air China Airlines Transport 151.85
399384 2017-07-02 13:14:58 Shelly Lawrence male 42 Ruby Tuesday Dining 98.97
399385 2017-07-04 12:50:29 Shelly Lawrence male 42 Xbox Entertainment 196.41
399386 2017-06-14 15:19:54 Shelly Lawrence male 42 Memrise Inc. Education 77.85
399387 2017-07-02 05:24:01 Shelly Lawrence male 42 Ikari Area Entertainment 141.45
399388 2017-06-12 21:44:31 Shelly Lawrence male 42 Maxim' s Catering Dining 170.22
399389 2017-07-05 23:00:57 Shelly Lawrence male 42 Cathay Pacific Airways Transport 261.03
399390 2017-06-18 01:09:32 Shelly Lawrence male 42 The UrbanTaxi Transport 194.27
399391 2017-06-25 11:18:41 Shelly Lawrence male 42 Colourmix Cosmetics Company Limited Beauty 179.55
399392 2017-06-21 14:44:41 Shelly Lawrence male 42 Hong Kong Airlines Transport 289.14
399393 2017-06-30 09:07:53 Shelly Lawrence male 42 Shinhan Financial Group Co Ltd Investment 30.52
399394 2017-06-18 08:01:17 Shelly Lawrence male 42 Raymond James Financial, Inc. Investment 173.41
399395 2017-06-29 19:57:30 Shelly Lawrence male 42 Costco Wholesale Corporation Grocery 225.21
399396 2017-06-15 22:27:55 Shelly Lawrence male 42 Code School LLC. Education 151.89
399397 2017-06-14 16:01:42 Shelly Lawrence male 42 Longchamp Clothing 157.49
399398 2017-06-21 09:21:27 Shelly Lawrence male 42 Costco Wholesale Corporation Grocery 57.18
399399 2017-06-29 11:00:01 Shelly Lawrence male 42 McDonald' s Dining 94.67

119000 rows × 7 columns


In [21]:
# prepare for the array
companies = pd.read_csv('label.csv')
company_names= list(companies.name)
company_names


Out[21]:
['Bobbi Brown Inc.',
 'Dior Beauty',
 'Derma Skincare Centre',
 'KIKO Asia Ltd.',
 'Vichy Laboratories',
 'Colourmix Cosmetics Company Limited',
 'Sa Sa Cosmetic Co. Ltd.',
 'Clinique Laboratories, llc.',
 'Shiseido Company, Limited',
 'Sephora USA, Inc.',
 'MAKE-UP ART COSMETICS.',
 'Clarins.',
 "L'Oreal SA",
 'Laura Mercier Cosmetics.',
 'FANCL International, Inc.',
 'Memrise Inc.',
 'Coursera Inc.',
 'Udacity, Inc.',
 'Code School LLC.',
 'edX Inc.',
 'Open Learning Global Pty Ltd.',
 'New Oriental Education & Tech Grp',
 'Chinese TAL Education Group',
 'Tarena International, Inc.',
 'Chegg Inc',
 '2U, Inc.',
 'McGraw-Hill Education',
 'Pearson plc',
 'China Distance Education Hldgs Ltd',
 'Udemy, Inc.',
 'YouTube',
 'Netflix, Inc.\xa0',
 'Spotify AB',
 'Youku Tudou Inc.',
 'iQIYI.COM',
 'Xiami.com',
 'KKBOX',
 'QQ Music',
 'Home Box Office Inc.',
 'Vudu, Inc.\xa0',
 'DIRECTV',
 'Redbox Automated Retail, LLC.\xa0',
 'BB Liquidating Inc',
 'Le.com',
 'Crackle, Inc.',
 'Marks and Spencer Group Plc',
 'Tesco PLC',
 'Wal-Mart Stores Inc',
 'Costco Wholesale Corporation',
 'Best Buy Co Inc',
 'Publix Super Markets',
 'Carrefour SA',
 'Rainbow Department Store Company Limited',
 'The Dairy Farm Company, Limited',
 'PARKnSHOP Supermarket HK.',
 'A.S. Watson Group (Hong Kong) Ltd.',
 'City Super Limited',
 'SOGO Limited.',
 'Mannings.',
 'AEON CO. LTD',
 'Rifle Paper Co.',
 'Staedtler Mars GmbH & Co. KG',
 'KOKUYO Co.,Ltd.',
 'PILOT CORPORATION',
 'Schwan-STABILO Group',
 'Faber-Castell',
 'Liberty Stationery Corp.\xa0',
 'Parker Pen Company',
 'Sakura Color Products Corporation',
 'Maped SAS',
 'Societe B I C SA',
 'The Ohio & Michigan Paper Company',
 'Hok Yee Stationery Company',
 '3M Company',
 'Shenzhen Comix Stationery Co., Ltd.',
 'The PNC Financial Services Group, Inc.',
 'Principal Financial Group Inc',
 'RAIT Financial Trust',
 'Raymond James Financial, Inc.',
 'Shinhan Financial Group Co Ltd',
 'Stifel Financial Corporation',
 'Sumitomo Mitsui Financial Group Inc',
 'Sun Life Financial Inc.',
 'Synovus Financial Corp.',
 'TCF Financial Corporation',
 'Voya Financial, Inc.',
 'Waddell & Reed Financial, Inc.',
 'Webster Financial Corporation',
 'Yadkin Financial Corporation',
 'ZAIS Financial Corp.',
 'Subway',
 "McDonald' s",
 'KFC',
 'Burger King',
 'Pizza Hut',
 "Maxim' s Catering",
 "Domino' s Pizza",
 'Pacific Coffee Company',
 'Din Tai Fung',
 'Ruby Tuesday',
 'Sizzler',
 'Yoshinoya',
 'Wing Wah',
 'Tim Ho Wan',
 'Café de Coral',
 'Mass Transit Railway (MTR)',
 'The Kowloon Motor Bus Company Limited',
 'Citybus Limited',
 'Long Win Bus Company Limited',
 'Uber',
 'Hong Kong Airlines',
 'Cathay Pacific Airways',
 'Hong Kong Express Airways Limited',
 'Hong Kong Dragon Airlines Ltd',
 'The UrbanTaxi',
 "The 'Star' Ferry Company, Limited",
 'Hong Kong Tramways, Limited',
 'Peak Tramways Company Limited',
 'New World First Bus Services Limited',
 'Air China Airlines',
 'Broadway Cinematheque',
 'UA Cinema Circuit Limited',
 'Neway Karaoke Box Limited',
 'Red MR Limited',
 'Walt Disney Company',
 'AMC Entertainment Inc',
 'Nintendo',
 'Xbox',
 'LEGO',
 'Ocean Park Hong Kong ',
 'Ryze Ultimate Trampoline Park Hong Kong',
 'Ball Room',
 'Ikari Area',
 'VR Arena',
 'HA cube',
 'American Eagle Outfitters Inc',
 'Holister Co.',
 'Zara',
 'H&M Hennes & Mauritz AB',
 'GAP',
 'Levi Strauss & Co. ',
 'G2000',
 'Louis Vuitton',
 'Longchamp',
 'J. Crew',
 'Nike',
 'Adidas',
 'Converse',
 'Superdry',
 'Balenciaga']

In [32]:
number_of_people = int(dfSameAge.shape[0] / 40)

allList = []
for i in range(number_of_people):
    currentList = []
    for j in range(40):
        row= dfSameAge.iloc[i*40+j]
        companyName = row['company name']
        
        companyIndex = company_names.index(companyName)
        oneHot = np.zeros(len(company_names))
        oneHot[companyIndex] = 1
        currentList.append(oneHot)
    allList.append(currentList)
np.array(allList).shape


Out[32]:
(2975, 40, 150)

In [35]:
np.save('ontHotEncoded.npy', allList)

In [ ]: