code: def mbox_to_pandas(mbox_path):
      
      if os.path.isfile(mbox_path):
          mbox_files = [mbox_path]
      else:
          mbox_files = [os.path.join(dirpath, f) for dirpath, dirnames, files in os.walk(mbox_path) for f in files if f.endswith('mbox')]
  
      mail_table = []
  
      f_pbar = tqdm.tqdm(range(0,len(mbox_files)))
      f_pbar.set_description('Extracting mbox files...')
  
      for mbox_file in mbox_files:
          write_table(mbox_file, mail_table)
          f_pbar.update(1)
  
      df_out = pd.DataFrame(mail_table)
      df_out.columns = ['From', 'To', 'Cc', 'Date', 'Subject', 'Body']
      df_out['NumTo'] = df_out['To'].map(lambda i: len(i))
      df_out['NumCC'] = df_out['Cc'].map(lambda i: len(i))
      return df_out
docs: Extracts all mbox messages from mbox files in mbox_path.
      :param mbox_path: Path to an mbox file OR a directory containing mbox files.
      :return: A Pandas DataFrame with messages as rows/observations.