nested

Create a pandas dataframe from a nested json file

Create a pandas dataframe from a nested json file Question: I have the following json file: { "data": { "start_date": "2022-10-01", "end_date": "2022-10-04", "cur": "EUR", "prizes": { "2022-10-01": { "coffee": 0.1448939471560284, "usd": 1 }, "2022-10-02": { "coffee": 0.14487923291390148, "usd":1 }, "2022-10-03": { "coffee": 0.1454857922753868, "usd": 1 } } } } I want to create a …

Total answers: 4

converting a deep nested loop from JSON into Pandas DF

converting a deep nested loop from JSON into Pandas DF Question: I am getting info from an API, and getting this as the resulting JSON file: {‘business_discovery’: {‘media’: {‘data’: [{‘media_url’: ‘a link’, ‘timestamp’: ‘2022-01-01T01:00:00+0000’, ‘caption’: ‘Caption’, ‘media_type’: ‘type’, ‘media_product_type’: ‘product_type’, ‘comments_count’: 1, ‘like_count’: 1, ‘id’: ‘ID’}, {‘media_url’: ‘link’, # … and so on # NOTE: …

Total answers: 1

Generate a dictionary with two-level keys from list

Generate a dictionary with two-level keys from list Question: Struggling to get the desired data structure. (Note – pandas implementation are preferred) Currently I have the following lists of dictionaries: list1 =[ {‘ip’: ‘11.22.33.44’, ‘timestamp’: 1665480231699, ‘message’: ‘{"body": "Idle time larger than time period. retry:0"}’, ‘ingestionTime’: 1665480263198}, {‘ip’: ‘11.22.33.42’, ‘timestamp’: 1665480231698, ‘message’: ‘{"body": "Idle time …

Total answers: 1

How can i calculate the sum of numbers in a nested dict. in python

How can i calculate the sum of numbers in a nested dict. in python Question: How can i calculate the sum or total points of numbers of this nested dict. in python i tried alot of things and it didn’t work all time get the last value in the loop not every grade or value. …

Total answers: 3

Python, list of nested repeated keys

Python, list of nested repeated keys Question: I would like to process this json data in python: {"data": [{"CU":"AGLD","CO": [{"chain":"ERC20"}], "fn":"Adventure Gold"}, {"CU":"ACH","CO": [{"chain":"ERC20"}, {"chain":"BEP20"}], "fn":"Alchemy"}]} I would like to get the value of all "chain"s. For example like this: CU chains: AGLD ERC20 ACH ERC20 ACH BEP20 I tried with a for loop, but …

Total answers: 2

How do I implement custom iterators so that I can nest them?

How do I implement custom iterators so that I can nest them? Question: I was just looking up some stuff about python iterators and stumbled across thisW3School iterator example example from w3school: class MyNumbers: def __iter__(self): self.a = 1 return self def __next__(self): if self.a <= 20: x = self.a self.a += 1 return x …

Total answers: 1

How to obtain the values of provided data in which a minimum value occurs in a list?

How to obtain the values of provided data in which a minimum value occurs in a list? Question: So I’ve been trying to select 2 parameters as a result in which the minimum value occurs in another calculation (the error below). Consider the following dummy code for better understanding: def min_error(par1, par2): output = {"parameters": …

Total answers: 1

Create many new column df, having a nested column inside that df

Create many new column df, having a nested column inside that df Question: I have a data frame that looks like this: a = {‘price’: [1, 2], ‘nested_column’: [[{‘key’: ‘code’, ‘value’: ‘A’, ‘label’: ‘rif1’}, {‘key’: ‘datemod’, ‘value’: ’31/09/2022′, ‘label’: ‘mod’}], [{‘key’: ‘code’, ‘value’: ‘B’, ‘label’: ‘rif2’}, {‘key’: ‘datemod’, ‘value’: ’31/08/2022′, ‘label’: ‘mod’}]]} df = pd.DataFrame(data=a) …

Total answers: 4

How to skip a line in a python nested list

How to skip a line in a python nested list Question: I was trying to make a code in pyh=thon, which contain a nested list. Each list will be in a different line. line1=list((0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)) line2=list((0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)) arena=list() arena.append(line1) arena.append(‘/n’) arena.append(line2) However the outpoot is [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …

Total answers: 1