code: def mavg(data, xseq, **params):
      """
      Fit moving average
      """
      window = params["method_args"]["window"]
  
      # The first average comes after the full window size
      # has been swept over
      rolling = data["y"].rolling(**params["method_args"])
      y = rolling.mean()[window:]
      n = len(data)
      stderr = rolling.std()[window:]
      x = data["x"][window:]
      data = pd.DataFrame({"x": x, "y": y})
      data.reset_index(inplace=True, drop=True)
  
      if params["se"]:
          dof = n - window  # Original - Used
          data["ymin"], data["ymax"] = tdist_ci(
              y, dof, stderr, params["level"]
          )
          data["se"] = stderr
  
      return data
  
imports: from __future__ import annotations
  import warnings
  from contextlib import suppress
  from typing import TYPE_CHECKING
  import numpy
  import pandas
  from .._utils import get_valid_kwargs
  from ..exceptions import PlotnineError, PlotnineWarning
label_desc: Use image node_id 12 for calling a global function with example usage: mavg(data, xseq) and returns: data