convert for loop to dictionary comprehension

Viewed 49

I'm trying to convert my for loop into dictionary comprehension but it seems to not work as dictionary comprehension can only change one key/value pair at a time.

def get_data(arr, target_time) ->pd.DataFrame:
   totalResult = pd.DataFrame()
   parameter = { "Period": "One Hour"}
   for value in arr:
      parameter.update(
         {
            "Test1": "dataset =$Prod$ metric_class=$ProcessPath$",
            "FunctionExpression": f"(AVG("value"))",
            "FunctionLabel": f"{value}_average_rate",
         }
      )
      phaseResult = get_data_from_database(parameter, target_time) ##internal function
      phaseResult = restructure_data(phaseResult, target_time, "mean", False) ## internal function
      totalResult = totalResult.append(phaseResult, sort=True)
   return totalResult
0 Answers
Related