Question: In Python create a hash of a hash using given CSV data. It will take a string array which is the output of your function
In Python create a hash of a hash using given CSV data.
It will take a string array which is the output of your function mydatatransform, it will return a json string of hash of hash following this format: COLUMN: Value: nbrofoccurenceofvalue Value: nbrofoccurenceofvalue Order of Column will be the order they are in the header of the CSV Gender first then Email, etc Order of the Value will be the order they appear in each line from top left. Use STRINGS as keys Do not use any symbol or any fancy things. It doesn't translate well in json. no :Age "Age"
So far I have this:
Expected Return Value Gender:Male:"Female":"Email":yahoocom":"hotmail.com":"Age"::::"City":Seattle:"Detroit":"Las Vegas":"Chicago":"Device":Safari iPhone":"Chrome Android":"Chrome":"Order At:afternoon:"morning":
Return Value Gender: Male: Female: Email: yahoocom: hotmailcom: Age: : : : City: Seattle: Detroit: Las Vegas: Chicago: Device: Safari iPhone: Chrome Android: Chrome: Order At: afternoon: morning:
code snip
import json
:type input: String
:rtype: string
def mydataprocessinput:
headers inputsplit
data linesplit for line in input:
# Filter headers
requiredheaders Gender "Email", "Age", "City", "Device", "Order At
requiredindices i for i header in enumerateheaders if header in requiredheaders
# Dictionary to count occurrences of each key value
counts header: for header in requiredheaders
# Process each row
for row in data:
for index in requiredindices:
header headersindex
value rowindexstrip
if value in countsheader:
countsheadervalue
else:
countsheadervalue
counts
return json.dumpscounts
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
