Python for loop through nested dictionary question?

Trying to loop through a nested dictionary and want to store values into name, age and occupation. Without manually creating those variables within the for loop. Is this even possible? Just trying to create cleaner looking code. Thank you. people = { 1: {"name": "Simon", "age": 20, "occupation": "Data scientist"}, 2: {"name": "Kate", "age": 30,… Read More Python for loop through nested dictionary question?

Flatten column within data frame containing nested dictionaries and lists

I have a pandas dataframe with 8 columns, one of which is made up of cells containing nested dictionaries and lists in the following format: {‘x1’: {‘y1’: [‘z1’, ‘z2’], ‘y2’: [‘z3’, ‘z4’, ‘z5’]}, ‘x2’: {‘y1’: [‘z6’, ‘z7’, ‘z8’], ‘y2’: [‘z9′, z10’]}} How can I transform this column so that the x-variables are melted with the… Read More Flatten column within data frame containing nested dictionaries and lists

Extracting data from nested dict in ansible with conditional checks in the list?

I’m stuck with the following issue. My JSON data looks like this: [ { "clusters":[ { "id":"1", "name":"cluster1" }, { "id":"2", "name":"cluster2" } ], "tag":"a" }, { "clusters":[ { "id":"3", "name":"cluster2" } ], "tag":"b" } ] What I am trying to do is extracting the tag values which are connected to a certain cluster (say,… Read More Extracting data from nested dict in ansible with conditional checks in the list?

Trying to push the contents of objects nested inside objects to an array (JavaScript)

When having objects nested inside objects I can’t loop through them with a regular for in loop. I googled and found I have to make a recursive function that would check if the property is an object. I wrote a recursive function like this: ` function isObject(value){ return (typeof(value)===’object’); } “ function listToArray(list){ let arr=[];… Read More Trying to push the contents of objects nested inside objects to an array (JavaScript)

How can I make this programme format the string properly? PHP – Nested For Loop

<?php $list = [‘a’, ‘b’, ‘c’]; $count = [1, 3, 5]; function stringFormatter($c, $i) { return "Char is $c & Int is $i"; } for ($i = 0; i < $list; $i++) { for ($j = 0; $j < $count; $j++) { $string = stringFormatter($list[$i], $count[$j]); print $string; } } ?> This is sample code… Read More How can I make this programme format the string properly? PHP – Nested For Loop

How to replace the values of nested lists stored in python dataframe?

I have the following dataframe data = [[[[[1, 2, 0], [1]],[[1, 2], [4]]], [[[[1, 2], [4]]]], [[[1]]]], [[[[1, 2, 0], [1]],[[1, 2], [4]]], [[[[1, 2], [4]]]], [[[1]]]]] df = pd.DataFrame(data) Also, I have a second dataframe df2: data2 = [[1, 10], [1, 15], [1, 14], [1, 20], [1, 18]] df2 = pd.DataFrame(data2, columns=[‘dir’, ‘line’]) The… Read More How to replace the values of nested lists stored in python dataframe?