Extracting average time series
Json should be put in a separate file.
myfile.json
{   &quot;cost&quot;:0,
   &quot;timespan&quot;:&quot;2020-07-07T03:00:00Z/2020-07-07T03:15:00Z&quot;,
   &quot;interval&quot;:&quot;TM&quot;,
   &quot;value&quot;:[      {         &quot;id&quot;:&quot;/subscriptions/hjhkjhjljkjknlkjjlkj/Groups/jhkjhjkhjs/providers/Micro/virtualMachines/jhjkhkjhjkhkhljkl/providers/MicInsights/metrics/Percentage CPU&quot;,
         &quot;type&quot;:&quot;Microsoft.Insights/metrics&quot;,
         &quot;name&quot;:{
            &quot;value&quot;:&quot;Percentage CPU&quot;,
            &quot;localizedValue&quot;:&quot;Percentage CPU&quot;
         
},
         &quot;displayDescription&quot;:&quot;The percentage of allocated compute units that are currently in use by the Virtual Machine(s)&quot;,
         &quot;unit&quot;:&quot;Percent&quot;,
         &quot;timeseries&quot;:[            {               &quot;metadatavalues&quot;:[

               
],
               &quot;data&quot;:[                  {
                     &quot;timeStamp&quot;:&quot;2020-07-07T03:00:00Z&quot;,
                     &quot;average&quot;:2.4659375
                  
},
                  {
                     &quot;timeStamp&quot;:&quot;2020-07-07T03:01:00Z&quot;,
                     &quot;average&quot;:2.974375
                  
},
                  {
                     &quot;timeStamp&quot;:&quot;2020-07-07T03:02:00Z&quot;,
                     &quot;average&quot;:2.90265625
                  
},
                  {
                     &quot;timeStamp&quot;:&quot;2020-07-07T03:03:00Z&quot;,
                     &quot;average&quot;:1.72484375
                  
},
                  {
                     &quot;timeStamp&quot;:&quot;2020-07-07T03:04:00Z&quot;,
                     &quot;average&quot;:1.1275
                  
},
                  {
                     &quot;timeStamp&quot;:&quot;2020-07-07T03:05:00Z&quot;,
                     &quot;average&quot;:0.05640625
                  
},
                  {
                     &quot;timeStamp&quot;:&quot;2020-07-07T03:06:00Z&quot;,
                     &quot;average&quot;:0.05515625
                  
},
                  {
                     &quot;timeStamp&quot;:&quot;2020-07-07T03:07:00Z&quot;,
                     &quot;average&quot;:0.055
                  
},
                  {
                     &quot;timeStamp&quot;:&quot;2020-07-07T03:08:00Z&quot;,
                     &quot;average&quot;:0.28765625
                  
},
                  {
                     &quot;timeStamp&quot;:&quot;2020-07-07T03:09:00Z&quot;,
                     &quot;average&quot;:0.0546875
                  
},
                  {
                     &quot;timeStamp&quot;:&quot;2020-07-07T03:10:00Z&quot;,
                     &quot;average&quot;:0.054375
                  
},
                  {
                     &quot;timeStamp&quot;:&quot;2020-07-07T03:11:00Z&quot;,
                     &quot;average&quot;:0.05734375
                  
},
                  {
                     &quot;timeStamp&quot;:&quot;2020-07-07T03:12:00Z&quot;,
                     &quot;average&quot;:0.0553125
                  
},
                  {
                     &quot;timeStamp&quot;:&quot;2020-07-07T03:13:00Z&quot;,
                     &quot;average&quot;:0.05609375
                  
},
                  {
                     &quot;timeStamp&quot;:&quot;2020-07-07T03:14:00Z&quot;,
                     &quot;average&quot;:0.0528125
                  
}
               
]
            
}
         
],
         &quot;errorCode&quot;:&quot;Success&quot;
      
}
   
],
   &quot;namespace&quot;:&quot;Microsoft/virtualMachines&quot;,
   &quot;resourceregion&quot;:&quot;eastus8&quot;
}

myfile.py
with open(&quot;myfile.json&quot;) as file_obj:
    formatted_response = json.load(file_obj)

Use descriptive identifiers for variables.
formatted_response_value = formatted_response['value']

Unnecessary double for loop
formatted_response_value = formatted_response['value']
timeseries = formatted_response_value[0][&quot;timeseries&quot;]   #please name something descriptive at all places. 
data = q[0][&quot;data&quot;]
average = list(map(lambda x:x[&quot;average&quot;], g))[-1] #or [entry[&quot;average&quot;] for entry in g][-1]