I need to write a output from aws account to excel sheet. I am using graphql and using jmespath.search to map the expressions and store in a excel sheet. I am facing issue with duplicate Id getting stored. I am using filter to merge two columns values into single columns values such as "active" or ""inactive". While storing the data I am getting duplicate Ids as well. I need to remove the duplicate id based on "inactive" status and add active Ids alone into a sheet.
For example let us take that response is coming in list format as below.
data = [
{"id": 1, "deregistered ": True, "deactivated":True, "location": true},
{"id": 1, "deregistered ": False, "deactivated": False, "location": true},
{"id": 2, "deregistered ": False, "deactivated":False, "location": true},
]
Now, I need to write this into excel sheet by removing the duplicate id based on status. I need only below values from the data. i.e remove the id 1 if it is duplicate and store only active ids.
output={'id':1, 'status' : 'active', 'location': true},{'id':2, 'status' : 'inactive', 'location': true}
How to achieve this using python but without pandas. and I am using jmespath.search and mapping the values.
I tried as below but not getting the logic.
for val in data:
loc_enabled = val.get("location")
if loc_enabled:
search = """
{
"id": id,
"status": ((deregistered == `true` || deactivated == `true`) && `Inactive`) || `Active`,
"location":location
}"""
test = jmespath.search(search, val)
if test:
loc_enabled.append(test)
print(loc_enabled)
I need to know where to handle the logic here without pandas. and get the desired results `