title: Split Large CSV or XLSX to Smaller ones with maximum filesize
body: <p>The main purpose of this script creation is the 40mb limit by email. When I schedule reports online, I don't get them in my inbox if they are larger than 40mb. So, I manually download the file, use the script below and then re-send the files. My issues is that I noticed that in the files, the dates are not consistent. </p>
  
  <p>01) I want to sort rows by date and for example have the first file have the earliest dates from the full file.</p>
  
  <p>02) I want to alter the script and split by the expected MB of each file and not rows</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import csv
  import sys
  import os
  
  def split(filehandler, delimiter=',', row_limit=70000,
            output_name_template='LARGE EXCEL/OUTPUT/output_%s.csv', output_path='.', keep_headers=True):
      import csv
      reader = csv.reader(filehandler, delimiter=delimiter)
      current_piece = 1
      current_out_path = os.path.join(
          output_path,
          output_name_template % current_piece
      )
      current_out_writer = csv.writer(open(current_out_path, 'w', newline=''), delimiter=delimiter)
      current_limit = row_limit
      if keep_headers:
          headers = next(reader)
          current_out_writer.writerow(headers)
      for i, row in enumerate(reader):
          if i + 1 &gt; current_limit:
              current_piece += 1
              current_limit = row_limit * current_piece
              current_out_path = os.path.join(
                  output_path,
                  output_name_template % current_piece
              )
              current_out_writer = csv.writer(open(current_out_path, 'w', newline=''), delimiter=delimiter)
              if keep_headers:
                  current_out_writer.writerow(headers)
          current_out_writer.writerow(row)
  
  split(open('LARGE EXCEL/FILE.csv', 'r'));
  </code></pre>