<p>如果您有多个数据条目,这将有所帮助</p>
<pre><code>lst = [{'data': [{'interval': '2021-09-22T09:13:57.000Z/2021-09-29T09:13:57.000Z',
'metrics': [{'metric': 'nOffered',
'qualifier': None,
'stats': {'count': 17,
'count_negative': None,
'count_positive': None,
'current': None,
'denominator': None,
'max': None,
'min': None,
'numerator': None,
'ratio': None,
'sum': None,
'target': None}},
{'metric': 'tAnswered',
'qualifier': None,
'stats': {'count': 17,
'count_negative': None,
'count_positive': None,
'current': None,
'denominator': None,
'max': 17327.0,
'min': 4569.0,
'numerator': None,
'ratio': None,
'sum': 156929.0,
'target': None}},
{'metric': 'tTalk',
'qualifier': None,
'stats': {'count': 29,
'count_negative': None,
'count_positive': None,
'current': None,
'denominator': None,
'max': 2650757.0,
'min': 2124.0,
'numerator': None,
'ratio': None,
'sum': 8402252.0,
'target': None}}],
'views': None}],
'group': {'mediaType': 'voice',
'queueId': 'a72dba75-0bc6-4a65-b120-8803364f8dc3'}}]
column_names = []
final_lst = []
for item in lst:
data_lst = []
for data in item['data']:
for metric in data['metrics']:
metric_name = metric['metric']
column_names.append(metric_name+'_count')
column_names.append(metric_name+'_sum')
data_lst.append(metric['stats']['count'])
data_lst.append(metric['stats']['sum'])
final_lst.append(data_lst)
df = pd.DataFrame(final_lst,columns=column_names)
print(df)
nOffered_count nOffered_sum tAnswered_count tAnswered_sum tTalk_count
0 17 None 17 156929.0 29
tTalk_sum
0 8402252.0
</code></pre>