Apply GZIP compression to a CSV in Python Pandas
问题 I am trying to write a dataframe to a gzipped csv in python pandas, using the following: import pandas as pd import datetime import csv import gzip # Get data (with previous connection and script variables) df = pd.read_sql_query(script, conn) # Create today's date, to append to file todaysdatestring = str(datetime.datetime.today().strftime('%Y%m%d')) print todaysdatestring # Create csv with gzip compression df.to_csv('foo-%s.csv.gz' % todaysdatestring, sep='|', header=True, index=False,