code: def vexec(f, v, vfuncs=None):
      r"""Add a variable to the given dataframe.
  
      This is the core function for adding a variable to a dataframe.
      The default variable functions are already defined locally
      in ``alphapy.transforms``; however, you may want to define your
      own variable functions. If so, then the ``vfuncs`` parameter
      will contain the list of modules and functions to be imported
      and applied by the ``vexec`` function.
  
      To write your own variable function, your function must have
      a pandas *DataFrame* as an input parameter and must return
      a pandas *DataFrame* with the new variable(s).
  
      Parameters
      ----------
      f : pandas.DataFrame
          Dataframe to contain the new variable.
      v : str
          Variable to add to the dataframe.
      vfuncs : dict, optional
          Dictionary of external modules and functions.
  
      Returns
      -------
      f : pandas.DataFrame
          Dataframe with the new variable.
  
      Other Parameters
      ----------------
      Variable.variables : dict
          Global dictionary of variables
  
      """
      vxlag, root, plist, lag = vparse(v)
      logger.debug("vexec : %s", v)
      logger.debug("vxlag : %s", vxlag)
      logger.debug("root  : %s", root)
      logger.debug("plist : %s", plist)
      logger.debug("lag   : %s", lag)
      if vxlag not in f.columns:
          if root in Variable.variables:
              logger.debug("Found variable %s: ", root)
              vroot = Variable.variables[root]
              expr = vroot.expr
              expr_new = vsub(vxlag, expr)
              estr = "%s" % expr_new
              logger.debug("Expression: %s", estr)
              # pandas eval
              f[vxlag] = f.eval(estr)
          else:
              logger.debug("Did not find variable: %s", root)
              # Must be a function call
              func_name = root
              # Convert the parameter list and prepend the data frame
              newlist = []
              for p in plist:
                  try:
                      newlist.append(int(p))
                  except:
                      try:
                          newlist.append(float(p))
                      except:
                          newlist.append(p)
              newlist.insert(0, f)
              # Find the module and function
              module = None
              if vfuncs:
                  for m in vfuncs:
                      funcs = vfuncs[m]
                      if func_name in funcs:
                          module = m
                          break
              # If the module was found, import the external transform function,
              # else search the local namespace and AlphaPy.
              if module:
                  ext_module = import_module(module)
                  func = getattr(ext_module, func_name)
              else:
                  modname = globals()["__name__"]
                  module = sys.modules[modname]
                  if func_name in dir(module):
                      func = getattr(module, func_name)
                  else:
                      try:
                          ap_module = import_module(
                              "alphapy.transforms"
                          )
                          func = getattr(ap_module, func_name)
                      except:
                          func = None
              if func:
                  # Create the variable by calling the function
                  f[v] = func(*newlist)
              elif func_name not in dir(builtins):
                  module_error = "*** Could not find module to execute function {} ***".format(
                      func_name
                  )
                  logger.error(module_error)
                  sys.exit(module_error)
      # if necessary, add the lagged variable
      if lag > 0 and vxlag in f.columns:
          f[v] = f[vxlag].shift(lag)
      # output frame
      return f
  
imports: from alphapy.alias import get_alias
  from alphapy.frame import Frame
  from alphapy.frame import frame_name
  from alphapy.globals import BSEP, LOFF, ROFF, USEP
  from alphapy.utilities import valid_name
  import builtins
  from collections import OrderedDict
  from importlib import import_module
  import logging
  import numpy
  import pandas
  import parser
  import re
  import sys
label_desc: Use image node_id 5 for calling a global function with example usage: vexec(f, v, vfuncs) and returns: f