Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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 andpersonalize 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, XXXXXXXXXX,26/2/2012, XXXXXXXXXX,WV,61309, XXXXXXXXXX,American Express,3491xxxxxxx1481,02/17,male,WATT,2,$ XXXXXXXXXX,3,$2099.83,8,$6030.52

Dr. Adam Taylor,male, XXXXXXXXXX,Thu Aug XXXXXXXXXX:03:34 GMT-0400 (Eastern Daylight Time), XXXXXXXXXX,Maryland, XXXXXXXXXX, XXXXXXXXXX,Diners Club United States & Canada,5454xxxxxxxx3035,03/24,male,WHQC,1,$299.69,2,$1269.94,4,$ XXXXXXXXXX

Dr. Mason Warner,male, XXXXXXXXXX,Thu Jan XXXXXXXXXX:27:28 GMT-0500 (Eastern Standard Time), XXXXXXXXXX,SC,14491, XXXXXXXXXX,Visa,4525xxxxxxxx7783,12/17,male,WENB,5,$3797.13,10,$ XXXXXXXXXX,12,$ XXXXXXXXXX

Miss Effie McBride,female, XXXXXXXXXX,20/10/2013, XXXXXXXXXX,C.A.,45311, XXXXXXXXXX,Diners Club United States & Canada,5423xxxxxxxx5443,04/25,female,KUYY,5,$2031.25,6,$ XXXXXXXXXX,10,$ XXXXXXXXXX

Dr. Marian Oliver,female, XXXXXXXXXX,Tue Jun XXXXXXXXXX:57:25 GMT-0400 (Eastern Daylight Time), XXXXXXXXXX,FL,19849, XXXXXXXXXX,Visa,4625xxxxxxxx0105,06/22,female,WXCT,3,$1761.26,5,$ XXXXXXXXXX,11,$ XXXXXXXXXX

Miss Blanche Frank,female, XXXXXXXXXX,Tue Aug XXXXXXXXXX:56:06 GMT-0400 (Eastern Daylight Time), XXXXXXXXXX,North Carolina, XXXXXXXXXX, XXXXXXXXXX,Mastercard,5106xxxxxxxx3706,04/22,female,WIED,3,$ XXXXXXXXXX,5,$ XXXXXXXXXX,9,$ XXXXXXXXXX

Doctor Alex Reeves,male, XXXXXXXXXX,12/26/2014, XXXXXXXXXX,KS, XXXXXXXXXX, XXXXXXXXXX,Discover Card,6011xxxxxxxx5088,01/23,male,KZSX,3,$1491.94,6,$ XXXXXXXXXX,16,$ XXXXXXXXXX

Miss Kate Glover,female, XXXXXXXXXX,Mon May XXXXXXXXXX:50:06 GMT-0400 (Eastern Daylight Time), XXXXXXXXXX,D.C.,71516-

Answered Same Day Oct 21, 2021

Solution

Neha answered on Oct 21 2021
154 Votes
import csv
with open('customerdata.csv', 'r', newline='') as f_input:
csv_input = csv.DictReader(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