code: def split_fraction_by_grain(
      df, fraction, time_column_name, grain_column_names=None
  ):
      if not grain_column_names:
          df["tmp_grain_column"] = "grain"
          grain_column_names = ["tmp_grain_column"]
  
      """Group df by grain and split on last n rows for each group."""
      df_grouped = df.sort_values(time_column_name).groupby(
          grain_column_names, group_keys=False
      )
  
      df_head = df_grouped.apply(
          lambda dfg: dfg.iloc[: -int(len(dfg) * fraction)]
          if fraction > 0
          else dfg
      )
  
      df_tail = df_grouped.apply(
          lambda dfg: dfg.iloc[-int(len(dfg) * fraction) :]
          if fraction > 0
          else dfg[:0]
      )
  
      if "tmp_grain_column" in grain_column_names:
          for df2 in (df, df_head, df_tail):
              df2.drop("tmp_grain_column", axis=1, inplace=True)
  
          grain_column_names.remove("tmp_grain_column")
  
      return df_head, df_tail
  
file_path: MachineLearningNotebooks/how-to-use-azureml/automated-machine-learning/forecasting-github-dau/helper.py
imports: import pandas
  from azureml.core import Environment
  from azureml.core.conda_dependencies import CondaDependencies
  from azureml.train.estimator import Estimator
  from azureml.core.run import Run
  from azureml.automl.core.shared import constants
label_desc: Use image node_id 1 for calling a global function with example usage: split_fraction_by_grain(df, fraction, time_column_name, grain_column_names) and returns: df_head,  df_tail