code: def create_df_file_with_query(self, query, output):
          
          chunk_size = 100000
          offset = 0
          data = defaultdict(lambda : defaultdict(list))
  
          with open(output, 'wb') as outfile:
              query = query.replace(';', '')
              query += """ LIMIT {chunk_size} OFFSET {offset};"""
              while True:
                  print(offset)
                  query = query.format(
                      chunk_size=chunk_size,
                      offset=offset
                  )
                  df = pd.read_sql(query, self.engine)
                  pickle.dump(df, outfile)
                  offset += chunk_size
                  if len(df) < chunk_size:
                      break
              outfile.close()
docs: Dumps in df in chunks to avoid crashes.