根据某些限制,我在某些地方会拜访每个地点。例如,我在every day
和morning
上学校noon
,而我不在weekends
上学校。
还有一个,我morning
的时间去过购物中心,所以我今天和以后几天可能都不会再去那里(我不在购物中心工作)。
我的问题是,是否有一种从数据集中选择正确位置的好方法,如:
location | types
MIT | 'school'
western union | 'accounting', 'finance'
Walmart | 'store', 'home_goods_store'
我知道每个地方的限制,取决于:
the time of the day
is it a working day
how long I've been there
the frequency of visiting
have I been there today? this week? this month?
每个位置的约束值都有不同的组合。
现在,我为每个约束使用了很多字典,但对于这么多if statements
有更好的方法吗?使用Python
编辑: 我的程序需要根据所有条件对每个活动进行分类。
freq_dic['low_freq'] = ['airport','atm','bank','dentist','doctor','hospital','zoo','jewelry_store','spa']
freq_dic['high_freq'] = ['grocery_or_supermarket','gym','home_goods_store','primary_school','school',
'secondary_school','shopping_mall','store','supermarket','university']
time_dic['morning'] = ['airport', 'atm','bakery','bank','beauty_salon','bicycle_store','book_store','cafe',
'clothing_store','dentist','doctor','drugstore','gym','hair_care','home_goods_store',
'hospital','jewelry_store','library','local_government_office','pharmacy','primary_school',
'school','secondary_school','shopping_mall','spa','store','supermarket','university','zoo']
time_dic['noon'] = ['atm','bakery','bank','beauty_salon','bicycle_store','book_store','cafe','clothing_store',
'convenience_store','dentist','department_store','doctor','drugstore','grocery_or_supermarket',
'gym','hair_care','home_goods_store','hospital','jewelry_store','library','local_government_office',
'primary_school','restaurant','school','secondary_school','shopping_mall','spa','store',
'supermarket','university']
time_dic['evening'] = ['bakery','bar','bicycle_store','cafe','convenience_store','department_store','drugstore',
'grocery_or_supermarket','gym','home_goods_store','hospital','jewelry_store','movie_theater',
'night_club','restaurant','shopping_mall','store','supermarket']
visited_today_dic = {}
...
对于数据集中的每一行,我隔离了时间和频率并将其发送到此函数:
def find_list(c_time, freq):
if 7 <= c_time <= 12:
if freq <= 6:
return list(set(time_dic['morning']).intersection(freq_dic['low_freq']))
elif freq <= 9:
return list(set(time_dic['morning']).intersection(freq_dic['med_freq']))
else:
return list(set(time_dic['morning']).intersection(freq_dic['high_freq']))
elif 12 < c_time <= 17:
if freq <= 6:
return list(set(time_dic['noon']).intersection(freq_dic['low_freq']))
elif freq <= 9:
return list(set(time_dic['noon']).intersection(freq_dic['med_freq']))
else:
return list(set(time_dic['noon']).intersection(freq_dic['high_freq']))
else:
if freq <= 6:
return list(set(time_dic['evening']).intersection(freq_dic['low_freq']))
elif freq <= 9:
return list(set(time_dic['evening']).intersection(freq_dic['med_freq']))
else:
return list(set(time_dic['evening']).intersection(freq_dic['high_freq']))
现在,对于每个活动,我从每个类别(时间,频率,访问,持续时间...)中选择合适的字典,并仅选择类型适合于字典中所有值的位置,即该活动是否具有每天的频率现在是早上,我今天还没去过那里,所以我将查看freq_dic['high_freq']
和time_dic['morning']
中的所有值,并仅选择常见的地方
TIA