Assistance greatly appreciated. sort seperate In order to use our customer data to our advantage, it needs to be organized. Please sort the information by last name, first name, sex, email address and...

1 answer below »

Assistance greatly appreciated. sort seperate


In order to use our customer data to our advantage, it needs to be organized.
Please sort the information by last name, first name, sex, email address and money spent in the last 12 months.
This will allow us to target our high spenders and send them a coupon code via email for our online market place. We can take this a step further and
personalize the coupon code based on sex, allow X amount off based on different categories.




This is in Python3 scripting. Using Codio


import csv
import re
data = []


with open('customerData.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
data.append(row)
print(data[0])
print(data[1]["Name"])
print(data[2]["Spent Past 30 Days"])



I added this to my script possibly wrong if so please assist.


firstName = str(input("What is your first name? "))
lastName = str(input("What is your last name? "))
lastFirstName = lastName + ', ' + firstName
print("Welcome", lastFirstName)


print time.strftime("%m/%d/%Y")


csvfile:


Name,Gender,SSN,Member Date,Phone,State,Zip,Email,Credit Card,Credit Card_Number,Credit Card Exp,Gender,Favorite Radio Station,Purchases Past 30 Days,Spent Past 30 Days,Purchases Past 6 Months,Spent Past 6 Months,Purchases Past 12 Months,Spent Past 12 Months


Steve Bryan,male,544-48-7885,26/2/2012,(581) 372-8004,WV,61309,[email protected],American Express,3491xxxxxxx1481,02/17,male,WATT,2,$943.9000000000001,3,$2099.83,8,$6030.52


Dr. Adam Taylor,male,756-71-5516,Thu Aug 01 2013 12:03:34 GMT-0400 (Eastern Daylight Time),(754) 394-9958,Maryland,47279-3797,[email protected],Diners Club United States & Canada,5454xxxxxxxx3035,03/24,male,WHQC,1,$299.69,2,$1269.94,4,$3253.6099999999997


Dr. Mason Warner,male,685-97-2592,Thu Jan 15 2015 18:27:28 GMT-0500 (Eastern Standard Time),7193934114,SC,14491,[email protected],Visa,4525xxxxxxxx7783,12/17,male,WENB,5,$3797.13,10,$10101.35,12,$15851.09


Miss Effie McBride,female,519-18-6381,20/10/2013,5783439312,C.A.,45311,[email protected],Diners Club United States & Canada,5423xxxxxxxx5443,04/25,female,KUYY,5,$2031.25,6,$5463.639999999999,10,$11522.880000000001


Dr. Marian Oliver,female,774-69-2230,Tue Jun 09 2009 07:57:25 GMT-0400 (Eastern Daylight Time),3893067428,FL,19849,[email protected],Visa,4625xxxxxxxx0105,06/22,female,WXCT,3,$1761.26,5,$5081.219999999999,11,$11918.49


Miss Blanche Frank,female,965-25-5537,Tue Aug 18 2015 10:56:06 GMT-0400 (Eastern Daylight Time),8666691755,North Carolina,74170-3501,[email protected],Mastercard,5106xxxxxxxx3706,04/22,female,WIED,3,$1248.6699999999998,5,$3529.1699999999996,9,$7512.039999999999


Doctor Alex Reeves,male,015-80-0822,12/26/2014,(616) 972-4752,KS,67010-7309,[email protected],Discover Card,6011xxxxxxxx5088,01/23,male,KZSX,3,$1491.94,6,$3398.4500000000003,16,$13353.35


Miss Kate Glover,female,496-35-9080,Mon May 20 2013 09:50:06 GMT-0400 (Eastern Daylight Time),6848521598,D.C.,71516-

Answered Same DayOct 21, 2021

Answer To: Assistance greatly appreciated. sort seperate In order to use our customer data to our advantage, it...

Neha answered on Oct 21 2021
144 Votes
import csv
with open('customerdata.csv', 'r', newline='') as f_input:
csv_input = csv.DictRead
er(f_input)
name = sorted(csv_input, key=lambda row: (row['Name']))

with open('sortedName.csv', 'w', newline='') as f_output:
csv_output = csv.DictWriter(f_output, fieldnames=csv_input.fieldnames)
csv_output.writeheader()
csv_output.writerows(name)
with open('customerdata.csv', 'r', newline='') as file:
csv_input =...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here