Skip to content

Instantly share code, notes, and snippets.

View aniruddha27's full-sized avatar

Aniruddha Bhandari aniruddha27

View GitHub Profile
df_food = pd.read_csv('C:\\Users\Dell\\Desktop\\train_food\\train_food.csv')
df_food.head()
df = pd.merge(df_food,df_center,on='center_id')
df = pd.merge(df,df_meal,on='meal_id')
table = pd.pivot_table(data=df,index='category',values='num_orders',aggfunc=np.sum)
table
#bar graph
plt.bar(table.index,table['num_orders'])
#xticks
plt.xticks(rotation=70
#x-axis labels
plt.xlabel('Food item'
#y-axis labels
#dictionary for meals per food item
item_count = {}
for i in range(table.index.nunique()):
item_count[table.index[i]] = table.num_orders[i]/df_meal[df_meal['category']==table.index[i]].shape[0]
#bar plot
plt.bar([x for x in item_count.keys()],[x for x in item_count.values()],color='orange')
#adjust xticks
#dictionary for cuisine and its total orders
d_cuisine = {}
#total number of order
total = df['num_orders'].sum()
#find ratio of orders per cuisine
for i in range(df['cuisine'].nunique()):
#cuisine
#pie plot
plt.pie([x*100 for x in d_cuisine.values()],labels=[x for x in d_cuisine.keys()],autopct='%0.1f',explode=[0,0,0.1,0])
#label the plot
plt.title('Cuisine share %')
plt.savefig('C:\\Users\\Dell\\Desktop\\AV Plotting images\\matplotlib_plotting_8.png',dpi=300,bbox_inches='tight')
plt.show();
#dictionary for base price per cuisine
c_price = {}
for i in df['cuisine'].unique():
c_price[i] = df[df['cuisine']==i].base_price
#plotting boxplot
plt.boxplot([x for x in c_price.values()],labels=[x for x in c_price.keys()])
#x and y-axis labels
plt.xlabel('Cuisine')
plt.ylabel('Price')
#plot title
plt.title('Analysing cuisine price')
#plotting histogram
plt.hist(df['base_price'],rwidth=0.9,alpha=0.3,color='blue',bins=15,edgecolor='red')
#x and y-axis labels
plt.xlabel('Base price range')
plt.ylabel('Distinct order')
#plot title
plt.title('Inspecting price effect')