<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Part 1 - Filter Categories
Step1:  For now, start from here...
Part 2 - Build Attribute Table
Step2:  Part 3 - Missing Values
(missing, not False)
Step3:  Part 4 - Join & output
<ASSISTANT_TASK:>
Python Code:
with open("./cat_food.txt", 'r') as fi:
    food = fi.read().splitlines()       
# Example: 
# target_cat = ['Restaurants', 'Food'] # to be continued...
target_cat = food
df = pd.read_pickle("./UC01_df_uc_open.p")
print df.shape
df = df[df.categories.apply(lambda x: not set(x).isdisjoint(set(target_cat)))]
print df.shape
Explanation: Part 1 - Filter Categories
End of explanation
# load data
# df = pd.read_pickle("./UC01_df_uc_open.p") 
df.index = df.business_id.values
att = df.attributes
# extract attributes
a = att.apply(lambda x: yaml.load('['+','.join(x)+']'))
# find full-size attribute set
# if subattribute exists, use '_' to connect them.
att_all = set()
for row in a:
    for i in row:
        if not isinstance(i.values()[0], dict):
            att_all.add(i.keys()[0])
        else:
            prefix = i.keys()[0]
            for k in i.values()[0].iterkeys():
                suffix = k
                temp = prefix + '_' + suffix
                att_all.add(temp)
len(att_all)
# create full-size attribute table
# index = business_id
# col = att_all
tab = pd.DataFrame(columns=att_all, index=df.index)
for ind in tab.index:
    for j in a[ind]:
        if not isinstance(j.values()[0], dict):
            tab.loc[ind, j.keys()[0]] = j.values()[0]
        else:
            prefix = j.keys()[0]
            for k, v in j.values()[0].iteritems():
                suffix = k
                temp = prefix + '_' + suffix
                tab.loc[ind, temp] = v
Explanation: For now, start from here...
Part 2 - Build Attribute Table
End of explanation
print tab.shape[0]
tab.count(axis=0).sort_values(ascending=False)[1:20]
# 729 * 50% = 360 -> 3 attributes -> RestaurantsPriceRange2 / BusinessParking / BikeParking 
print tab.shape[1]
tab.count(axis=1).sort_values(ascending=False)[1:20]
pl.violinplot(tab.count(axis=1).values,vert=False)
Explanation: Part 3 - Missing Values
(missing, not False)
End of explanation
# sort column by alphabeta
tab.columns = tab.columns.sort_values()
# shape
print df.shape, tab.shape
# join two table
df_with_attribute = df.join(tab)
df_with_attribute.to_pickle("./UC02_df_uc_food_att.p")
Explanation: Part 4 - Join & output
End of explanation
<END_TASK>