I'm trying to run to a loop (column in a dataframe) over a function which returns a list of dictionary and should store the result of each of the iteration in a separate list for each of the values in a column.
Example:
name id type
a 1 sol
b 2 sol
c 3 sol
I have tried the below code but I'm not getting any result
for id in df:
name_id = []
name_id.append(getAct(67,id,'pow','gen'))
Output
[{'status': 'success', 'message': 'success', 'data': []}]
def getAct(client_id, plant_id, tag_name, type_name):
api_endpoint = ''
today = datetime.date.today()
headers = {'token': get_token()['access_token'],
'Content-Type': 'application/json'}
params = {'client_id': str(client_id),
'from-date': str(today),
'to-date': str(today),
'tag': str(tag_name),
'type': str(type_name),
'plant-id': str(plant_id)
}
r = requests.post(url=api_endpoint, headers=headers, params=params)
return r.json()
An example of getAct function:
getAct(67,1,'pow','gen')
[{'utc_time': '2020-05-01 14:51:54',
'value': -0.02,
'insert': '2020-05-01 20:31:16'},
{'utc_time': '2020-05-01 14:52:51',
'value': -0.02,
'insert': '2020-05-01 20:31:21'}]
Expected Output
a_1 = [{'utc_time': '2020-05-01 14:51:54',
'value': -0.02,
'insert': '2020-05-01 20:31:16'},
{'utc_time': '2020-05-01 14:52:51',
'value': -0.02,
'insert': '2020-05-01 20:31:21'}]
b_2 = [{'utc_time': '2020-05-01 14:51:54',
'value': 4.02,
'insert': '2020-05-01 20:31:16'},
{'utc_time': '2020-05-01 14:52:51',
'value': 4.02,
'insert': '2020-05-01 20:31:21'}]
c_3 = [{'utc_time': '2020-05-01 14:51:54',
'value': 6.9,
'insert': '2020-05-01 20:31:16'},
{'utc_time': '2020-05-01 14:52:51',
'value': 7.3,
'insert': '2020-05-01 20:31:21'}]
I'm new to Python. Please help!
getActcoming from?id. Each of the list of dictionaries in the expected output corresponds to the id number which is being passed as argument in the function.getActis coming from an API. I'm adding the function for your kind perusal and needful.