I have a used a few different methods to get my list of dictionaries to a single dictionary and they all work without throwing errors, but the problem is that no matter the method, my values go missing!
I have a json:
[{"Query Fields Used":null,"History Connection Name":null,"History Query Run Count":"138,036"},
{"Query Fields Used":"[\"shifts.date_date\", \"hifts.sum_booked_shifts\"]","History Connection Name":"sandy","History Query Run Count":"59,069"},
{"Query Fields Used":"[\"daily_supply_v2.sum_booked_shifts\", \"daily_supply_v2.date_date\"]","History Connection Name":"low","History Query Run Count":"50,259"},
{"Query Fields Used":"[\"daily_supply_v2.date_date\", \"daily_supply_v2.sum_booked_shifts\"]","History Connection Name":"sandy","History Query Run Count":"50,235"},
{"Query Fields Used":"[\"orders.count_loads\", \"orders.complete_timestamp_date\"]","History Connection Name":"sandy","History Query Run Count":"29,658"},
{"Query Fields Used":"[\"hitch_stack.date_date\", \"hitch_stack.hitch_count\"]","History Connection Name":"low","History Query Run Count":"24,928"}]
I imported this with pandas.read_json. The Query Field's came in as a single string, so I removed all special characters with regex sub and then split by comma to get it to a list.
xx =[]
for i in looker['Query Fields Used']:
xx.append(i)
yy = []
for i in xx:
if i==None:
yy.append("None")
else:
x = re.sub(r'[^a-zA-Z0-9_.,]','', i)
yy.append(x)
y = []
for i in yy:
if i==None:
y.append("None")
else:
y.append(i.split(","))
looker['Query Fields Used'] = y
then I ran
d = [{key: val} for key, val in zip(looker['History Connection Name'], looker['Query Fields Used'])]
Which gave my the right keys, but the values stopped populating. I also tried creating a list of dictionaries and imported funcy
with a join and it gave the exact same results.
I am looking for a dictionary with values that contain all of the values from the corresponding lists, but only getting a few. What am I doing wrong here?