In [1]:
import pandas as pd
import numpy as np
In [74]:
df = pd.read_csv('BB_main.csv')
df1 = pd.read_csv('BB_main_1.csv')
df2 = pd.read_csv('BB_main_2.csv')
df3 = pd.read_csv('BB_main_3.csv')
In [75]:
print df.shape
df2.id.duplicated().sum()
Out[75]:
In [76]:
df = df.drop('Unnamed: 0', 1)
In [77]:
print df1.shape
df1 = df1.drop('Unnamed: 0', 1)
df.id.duplicated().sum()
Out[77]:
In [78]:
print df2.shape
df2 = df2.drop('Unnamed: 0', 1)
df2.head(3)
Out[78]:
In [79]:
print df3.shape
df3 = df3.drop('Unnamed: 0', 1)
df3.head(3)
Out[79]:
In [80]:
#concatenate the main tables.
BB_main= pd.concat([df, df1, df2, df3], join = 'outer', axis = 0, ignore_index = True)
#create a new dataframe with selected columns
BB_main_reduced = BB_main.drop(['recipeName', 'sourceDisplayName'], axis = 1)
In [81]:
#peek at dataframe
print BB_main.shape
BB_main.head(3)
Out[81]:
In [82]:
for i in BB_main.duplicated('id'):
if i == True:
print i
BB_main = BB_main.drop_duplicates('id')
BB_main.shape
Out[82]:
In [83]:
fdf = pd.read_csv('BB_flavors.csv')
fdf1 = pd.read_csv('BB_flavors_1.csv')
fdf2 = pd.read_csv('BB_flavors_2.csv')
fdf3 = pd.read_csv('BB_flavors_3.csv')
In [84]:
print fdf.shape
fdf = fdf.drop('Unnamed: 0', 1)
fdf = fdf.rename(columns = {'index':'id'})
fdf1.id.duplicated().sum()
Out[84]:
In [85]:
print fdf1.shape
fdf1 = fdf1.drop('Unnamed: 0', 1)
fdf1.head(3)
Out[85]:
In [86]:
print fdf2.shape
fdf2 = fdf2.drop('Unnamed: 0', 1)
fdf2 = fdf2.rename(columns = {'index':'id'})
fdf2.id.duplicated().sum()
Out[86]:
In [87]:
print fdf3.shape
fdf3 = fdf3.drop('Unnamed: 0', 1)
fdf3 = fdf3.rename(columns = {'index':'id'})
fdf3.id.duplicated().sum()
Out[87]:
In [88]:
#concatenate the flavors tables.
BB_flavors= pd.concat([fdf, fdf1, fdf2, fdf3], join = 'outer', axis = 0, ignore_index = True)
In [89]:
#peek at dataframe
print BB_flavors.shape
BB_flavors.head(2)
Out[89]:
In [90]:
for i in BB_flavors.duplicated('id'):
if i == True:
print i
BB_flavors = BB_flavors.drop_duplicates('id')
BB_flavors.shape
Out[90]:
In [91]:
cdf = pd.read_csv('BB_cuisines.csv')
cdf1 = pd.read_csv('BB_cuisines_1.csv')
cdf2 = pd.read_csv('BB_cuisines_2.csv')
cdf3 = pd.read_csv('BB_cuisines_3.csv')
In [92]:
print cdf.shape
cdf = cdf.drop('Unnamed: 0', 1)
cdf = cdf.rename(columns = {'index':'id'})
print cdf.columns
cdf.id.duplicated().sum()
Out[92]:
In [93]:
print cdf1.shape
cdf1 = cdf1.drop('Unnamed: 0', 1)
print cdf1.columns
cdf1.id.duplicated().sum()
Out[93]:
In [94]:
print cdf2.shape
cdf2 = cdf2.drop('Unnamed: 0', 1)
cdf2 = cdf2.rename(columns = {'index':'id'})
print cdf2.columns
cdf2.id.duplicated().sum()
Out[94]:
In [95]:
print cdf3.shape
cdf3 = cdf3.drop('Unnamed: 0', 1)
cdf3 = cdf3.rename(columns = {'index':'id'})
print cdf3.columns
cdf3.id.duplicated().sum()
Out[95]:
In [96]:
#concatenate the cuisines tables.
BB_cuisines= pd.concat([cdf, cdf1, cdf2, cdf3], join = 'outer', axis = 0, ignore_index = True)
In [97]:
#peek at dataframe
print BB_cuisines.shape
BB_cuisines.head(3)
Out[97]:
In [98]:
for i in BB_cuisines.duplicated('id'):
if i == True:
print i
BB_cuisines = BB_cuisines.drop_duplicates('id')
BB_cuisines.shape
Out[98]:
In [99]:
ddf = pd.read_csv('BB_details.csv')
ddf1 = pd.read_csv('BB_details_1.csv')
ddf2 = pd.read_csv('BB_details_2.csv')
ddf3 = pd.read_csv('BB_details_3.csv')
In [100]:
len(set(ddf3.id) & set(ddf2.id))
Out[100]:
In [101]:
print ddf.shape
ddf = ddf.drop('Unnamed: 0', 1)
print ddf.columns
ddf.id.duplicated().sum()
Out[101]:
In [102]:
print ddf1.shape
ddf1 = ddf1.drop('Unnamed: 0', 1)
print ddf1.columns
ddf1.id.duplicated().sum()
Out[102]:
In [103]:
print ddf2.shape
ddf2 = ddf2.drop('Unnamed: 0', 1)
print ddf2.columns
ddf2.id.duplicated().sum()
Out[103]:
In [104]:
print ddf3.shape
ddf3 = ddf3.drop('Unnamed: 0', 1)
print ddf3.columns
ddf3.id.duplicated().sum()
Out[104]:
In [105]:
#concatenate the details tables.
BB_details= pd.concat([ddf, ddf1, ddf2, ddf3], join = 'outer', axis = 0, ignore_index = True)
In [106]:
#peek at dataframe
print BB_details.shape
BB_details.head(3)
Out[106]:
In [107]:
for i in BB_details.duplicated('id'):
if i == True:
print i
BB_details = BB_details.drop_duplicates('id')
BB_details.shape
Out[107]:
In [108]:
idf = pd.read_csv('BB_ingredients.csv')
idf1 = pd.read_csv('BB_ingredients_1.csv')
idf2 = pd.read_csv('BB_ingredients_2.csv')
idf3 = pd.read_csv('BB_ingredients_3.csv')
In [109]:
len(set(idf2.id) & set(idf.id))
Out[109]:
In [110]:
print idf.shape
idf = idf.drop('Unnamed: 0', 1)
print idf.columns
idf.id.duplicated().sum()
Out[110]:
In [111]:
print idf1.shape
idf1 = idf1.drop('Unnamed: 0', 1)
print idf1.columns
idf1.id.duplicated().sum()
Out[111]:
In [112]:
print idf2.shape
idf2 = idf2.drop('Unnamed: 0', 1)
print idf2.columns
idf2.id.duplicated().sum()
Out[112]:
In [113]:
print idf3.shape
idf3 = idf3.drop('Unnamed: 0', 1)
print idf3.columns
idf3.id.duplicated().sum()
Out[113]:
In [114]:
#concatenate the ingredients tables.
BB_ing= pd.concat([idf, idf1, idf2, idf3], join = 'outer', axis = 0, ignore_index = True)
#create a new dataframe with selected columns
BB_ing_reduced = BB_ing[['id', 'ingredient_list']]
In [115]:
#make id first column
cols = list(BB_ing)
cols.insert(0, cols.pop(cols.index('id')))
BB_ing = BB_ing.ix[:, cols]
In [116]:
BB_ing.head(3)
Out[116]:
In [117]:
for i in BB_ing.duplicated('id'):
if i == True:
print i
BB_ing = BB_ing.drop_duplicates('id')
BB_ing.shape
Out[117]:
In [118]:
# set index to column 'id'
_df = [BB_main, BB_main_reduced, BB_cuisines, BB_flavors, BB_details, BB_ing, BB_ing_reduced]
for df in _df:
df.set_index('id', inplace = True)
In [119]:
# join dataframes
BB_data = BB_main.join([BB_cuisines, BB_flavors, BB_details, BB_ing])
BB_data_reduced = BB_main_reduced.join([BB_flavors, BB_details, BB_ing_reduced])
# add course column-Breakfast&Brunch
BB_data['course'] = 'Breakfast_Brunch'
BB_data_reduced['course'] = 'Breakfast_Brunch'
In [54]:
print BB_data.shape
BB_data.head(3)
Out[54]:
In [120]:
# save to csv
BB_data.to_csv('BB_Data.csv')
BB_data_reduced.to_csv('BB_data_reduced.csv')