-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathYelp_user.py
211 lines (147 loc) · 6.75 KB
/
Yelp_user.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
@author: sbhange
"""
import pandas as pd
# Read the yelp_user file ti dataframe
yelp_user_orig = pd.read_csv('/Users/sbhange/yelp_data/yelp_user.csv', keep_default_na=False)
# Create file for month 20180731
yelp_user_20180731 = yelp_user_orig[['user_id',
'name',
'review_count',
'yelping_since',
'useful',
'funny',
'cool',
'fans',
'elite',
'average_stars',
'compliment_hot',
'compliment_more',
'compliment_profile',
'compliment_cute',
'compliment_list',
'compliment_note',
'compliment_plain',
'compliment_cool',
'compliment_funny',
'compliment_writer',
'compliment_photos'
]]
# Add the date column and set the date
yelp_user_20180731['date']='2018-07-31'
yelp_user_20180731.to_csv('/Users/sbhange/yelp_data/yelp_user_20180731.csv')
# Create file for month 20180831
yelp_user_20180831 = yelp_user_orig[['user_id',
'name',
'review_count',
'yelping_since',
'useful',
'funny',
'cool',
'fans',
'elite',
'average_stars',
'compliment_hot',
'compliment_more',
'compliment_profile',
'compliment_cute',
'compliment_list',
'compliment_note',
'compliment_plain',
'compliment_cool',
'compliment_funny',
'compliment_writer',
'compliment_photos'
]]
# Add the date column and set the date
yelp_user_20180831['date']='2018-08-31'
# Divide the data frame into 2 data sets
yelp_user_20180831_1325600 = yelp_user_20180831[:1325600]
yelp_user_20180831_500 = yelp_user_20180831[1325600:]
# Dummy update the average_stars field
yelp_user_20180831_500['average_stars'] = 4.5
# Dummy update the fans field
yelp_user_20180831_500['fans'] = 10
# Dummy update the elite field
yelp_user_20180831_500['elite'] = '2015 2016 2017'
# Dummy update the useful field
yelp_user_20180831_500['useful'] = 2500
# Manually edit/add new records to datarframe for new user entry every month
yelp_user_20180831_updated = pd.concat([yelp_user_20180831_1325600, yelp_user_20180831_500], axis=0)
yelp_user_20180831_updated.to_csv('/Users/sbhange/yelp_data/yelp_user_20180831.csv')
# Create file for month 20180930
yelp_user_20180930 = yelp_user_orig[[ 'user_id',
'name',
'review_count',
'yelping_since',
'useful',
'funny',
'cool',
'fans',
'elite',
'average_stars',
'compliment_hot',
'compliment_more',
'compliment_profile',
'compliment_cute',
'compliment_list',
'compliment_note',
'compliment_plain',
'compliment_cool',
'compliment_funny',
'compliment_writer',
'compliment_photos'
]]
# Add the date column and set the date
yelp_user_20180930['date']='2018-09-30'
# Divide the data frame into 2 data sets
yelp_user_20180930_1325600 = yelp_user_20180930[:1325600]
yelp_user_20180930_500 = yelp_user_20180930[1325600:]
# Dummy update the average_stars field
yelp_user_20180930_500['average_stars'] = 3.5
# Dummy update the fans field
yelp_user_20180930_500['fans'] = 20
# Dummy update the elite field
yelp_user_20180930_500['elite'] = '2015 2016 2018'
# Dummy update the fans useful
yelp_user_20180930_500['useful'] = 3000
# Manually edit/add new records to datarframe
yelp_user_20180930_updated = pd.concat([yelp_user_20180930_1325600, yelp_user_20180930_500], axis=0)
yelp_user_20180930_updated.to_csv('/Users/sbhange/yelp_data/yelp_user_20180930.csv')
# Create file for month 20181031
yelp_user_20181031 = yelp_user_orig[[ 'user_id',
'name',
'review_count',
'yelping_since',
'useful',
'funny',
'cool',
'fans',
'elite',
'average_stars',
'compliment_hot',
'compliment_more',
'compliment_profile',
'compliment_cute',
'compliment_list',
'compliment_note',
'compliment_plain',
'compliment_cool',
'compliment_funny',
'compliment_writer',
'compliment_photos'
]]
yelp_user_20181031_500['useful'] = 3400
181031 = pd.read_csv('/Users/sbhange/yelp_data/yelp_user_20181031.csv', keep_default_na=False)
yelp_user_20181031['date']='2018-10-31'
list(yelp_user_20181031)
yelp_user_20181031_1325600 = yelp_user_20181031[:1325600]
yelp_user_20181031_500 = yelp_user_20181031[1325600:]
yelp_user_20181031_500['average_stars'] = 4
yelp_user_20181031_500['fans'] = 40
yelp_user_20181031_500['elite'] = '2015 2017 2018'
# Manually edit/add new records to datarframe
yelp_user_20181031_updated = pd.concat([yelp_user_20181031_1325600, yelp_user_20181031_500], axis=0)
yelp_user_20181031_updated.to_csv('/Users/sbhange/yelp_data/yelp_user_20181031.csv')