I want to create my dataframe which looks like this:
employeeId firstName lastName emailAddress isDependent employeeIdTypeCode entityCode sour
Not really a Pandas solution but kinds works:
Starts from your result
dataframe
from collections import defaultdict
import json
result = 'your data frame'
dicted = defaultdict(dict)
for r in result.values.tolist():
identifierValue, firstName, lastName, emailAddress,isDependent,\
identityTypeCode, entityCode, sourceCode,roleCode = r
tupled_criteria = (firstName,lastName,emailAddress)
if dicted[tupled_criteria].get("individualInfo"):
pass
else:
dicted[tupled_criteria]["individualInfo"] = {}
dicted[tupled_criteria]["individualInfo"]['entityCode'] = entityCode
dicted[tupled_criteria]["individualInfo"]['soruceCode'] = sourceCode
dicted[tupled_criteria]["individualInfo"]['roleCode'] = roleCode
dicted[tupled_criteria]["individualInfo"]['isDependent'] = isDependent
if dicted[tupled_criteria]["individualInfo"].get("individualIdentifier"):
pass
else:
dicted[tupled_criteria]["individualInfo"]["individualIdentifier"] = []
dicted[tupled_criteria]["individualInfo"]["individualIdentifier"]\
.append({"identityTypeCode":identityTypeCode,
"identifierValue":identifierValue,
"profileInfo":{
"firstName":firstName,
"lastName":lastName,
"emailAddress":emailAddress}})
for k,v in dicted.items():
print(k,'\n',json.dumps(v),'\n\n')