In [1]:
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'shopping_cart_project.settings'
from shopping_cart.models import *
from django.shortcuts import *
In [2]:
import pandas as pd
In [26]:
shipping = {'ground': 4.35, 'snail': 14.43, 'owl': 5.00, 'teleporter':324.04, 'pony_express':45.28}
In [27]:
cart =[
{'item_id': u'4', 'price': u'10.5', 'name': u'Eye Patch', 'quantity': u'1', 'shipping':'ground'},
{'item_id': u'1', 'price': u'10000', 'name': u'Time', 'quantity': u'1', 'shipping':'ground'},
{'item_id': u'7', 'price': u'800', 'name': u'Fender Strat', 'quantity': u'1','shipping':'ground'},
{'item_id': u'7', 'price': u'800', 'name': u'Fender Strat', 'quantity': u'1', 'shipping':'ground'}]
In [28]:
df = pd.DataFrame(cart, dtype=np.float16)
In [29]:
df
Out[29]:
In [49]:
tax = .1
In [50]:
df['shipping_costs'] = df.shipping.apply(lambda x: shipping[x])
df['tax'] = (((df.price * df.quantity)+ df.shipping_costs ) * tax)
df['total_price'] = ((df.price * df.quantity) + df.tax + df.shipping_costs)
In [51]:
df
Out[51]:
In [35]:
Out[35]:
In [39]:
total = df.total_price.sum()
a = [((df.price * df.quantity).sum()/ total),
df.shipping_costs.sum() / total,
df.tax.sum() / total]
In [46]:
a
Out[46]:
In [15]:
df.to_dict()
Out[15]:
In [ ]:
import pandas as pd
shipping = {'ground': 4.35, 'snail': 14.43, 'owl': 5.00, 'teleporter':324.04, 'pony_express':45.28}
tax = .08
df = pd.DataFrame(cart, dtype=np.float16)
df['shipping_costs'] = df.shipping.apply(lambda x: shipping[x])
df['tax'] = ((df.price * df.quantity) * tax)
df['total_price'] = ((df.price * df.quantity) + df.tax + df.shipping_costs)
df.to_json()