code: def traffic_light_summary(row, cols=None, prefix: str = ""):
      """Make a summary of traffic light alerts present in the dataframe
  
      Count number of green, yellow and red traffic lights.
  
      Evaluate with df.apply(traffic_light_summary, axis=1)
  
      :param pd.Series row: row to calculate traffic light summary of.
      :param list cols: list of cols to calculate traffic light summary of (optional)
      :param str prefix: prefix of traffic light columns, in case cols is empty. default is ``"tl_"``
      """
      x = {"n_red": np.nan, "n_yellow": np.nan, "n_green": np.nan}
  
      if cols is None or len(cols) == 0:
          # if no columns are given, find traffic light columns for which summary is made.
          cols = (
              [m for m in row.index.to_list() if m.startswith(prefix)]
              if prefix
              else row.index.to_list()
          )
      if len(cols) == 0:
          return pd.Series(x)
  
      traffic_lights = np.array([row[c] for c in cols])
      x["n_red"] = (traffic_lights == 2).sum()
      x["n_yellow"] = (traffic_lights == 1).sum()
      x["n_green"] = (traffic_lights == 0).sum()
      return pd.Series(x)
  
imports: from __future__ import annotations
  import copy
  import fnmatch
  from collections import defaultdict
  from typing import Any
  import numpy
  import pandas
  from popmon.analysis.apply_func import ApplyFunc
  from popmon.base import Module, Pipeline
label_desc: Use image node_id 1 for calling a global function with example usage: traffic_light_summary(row, cols, prefix) and returns: pd, pd