SHARE
TWEET

Untitled

a guest Oct 19th, 2019 122 in 1 day
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import csv
  2.  
  3. #lists needed for the script
  4. data = []
  5. amexlist = []
  6. highspendlist = []
  7.  
  8.  
  9. #read file
  10. with open('customerData.csv') as csvfile:
  11.     reader = csv.DictReader(csvfile)
  12.     for row in reader:
  13.         data.append(row)
  14.  
  15. #function to format credit card info into readable list with only relavent data, purchase amount cleaned up
  16. def compileinfo(list):
  17.   for i in list:
  18.     print('Customer name:', i['Name'], '\nNumber of purchases in previous 6 months:', i['Purchases Past 6 Months'], '\nAmount spent by customer in past 6 months:$%.2f'  %float(i['Spent Past 6 Months'].strip('$')), '\nContact email:', i['Email'], '\nContact phone number:', i['Phone'], '\n\n')
  19.  
  20.  
  21. #iteration to sort out American Express Users
  22. for i in data:
  23.   if i['Credit Card'] == 'American Express':
  24.     amexlist.append(i)
  25.  
  26.    
  27. #iteration to sort out high spenders
  28. for i in amexlist:
  29.   if float(i['Spent Past 6 Months'].strip('$')) > 4000.00:
  30.     highspendlist.append(i)
  31.  
  32.  
  33. #displaying data for ecommerce manager
  34. print(' Customer Data:  \n --------American Express Users--------\n\n')
  35. compileinfo(amexlist)
  36. print('--------Statistics--------\n\n')
  37. print('Total number of customers:', len(data))
  38. print('Total number of customers using American Express:', len(amexlist))
  39. print('Total number of American Express customers with high spend value:', len(highspendlist),'\n\n')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top