[ad_1]
#Q2 – Determine the proportion of each customer segment
segment_count=df['customer segment'].value_counts()
total_segment_count=segment_count['Home Office']+segment_count['Consumer']+segment_count['Corporate']
print("Home Office:",segment_count['Home Office']/total_segment_count*100,"%")
print("Corporate:",segment_count['Corporate']/total_segment_count*100,"%")
print("Consumer:",segment_count['Consumer']/total_segment_count*100,"%\n")
###Q3 – Which three products had the most sales
sales=df.groupby(['product name']).sum().sort_values("order item total",ascending=False)
sales=sales['order item total'][:3]
print(sales)
print()
###Q4 – For each transaction type, determine the average item cost before discount
transaction_type=df['type'].value_counts()
# print(transaction_type)
total_cost=[0,0,0,0]
total_quantity=[0,0,0,0]
for row in df.iterrows():
if row[1]['type']=='PAYMENT':
total_cost[0]+=row[1]['order item product price']
total_quantity[0]+=row[1]['order item quantity']
if row[1]['type']=='TRANSFER':
total_cost[1]+=row[1]['order item product price']
total_quantity[1]+=row[1]['order item quantity']
if row[1]['type']=='DEBIT':
total_cost[2]+=row[1]['order item product price']
total_quantity[2]+=row[1]['order item quantity']
if row[1]['type']=='CASH':
total_cost[3]+=row[1]['order item product price']
total_quantity[3]+=row[1]['order item quantity']
print("Average for transaction type PAYMENT is:\n",total_cost[0]/transaction_type[0],"\n",total_quantity[0]/transaction_type[0])
print("Average for transaction type TRANSFER is:\n",total_cost[1]/transaction_type[1],"\n",total_quantity[1]/transaction_type[1])
print("Average for transaction type DEBIT is:\n",total_cost[2]/transaction_type[2],"\n",total_quantity[2]/transaction_type[2])
print("Average for transaction type CASH is:\n",total_cost[3]/transaction_type[3],"\n",total_quantity[3]/transaction_type['CASH'])
print()
###Q5 – What is the most regular customer first name in Puerto Rico
country=df.where(df['customer country']=='Puerto Rico').dropna()
name=country['customer fname'].value_counts(ascending=False)
print("Most regular customer in Puerto Rico:",name[:1])
[ad_2]