I have a csv with the size equal to 170kB, and when I convert them to the parquet file, the size is 1.2MB. The data structure is 12 columns with strings.
import pandas as pd
import pyarrow as pa
import pyarrow.parquet as pq
csv_filename = "../files/test.csv"
parquet_filename = '../files/sample.parquet'
chunksize = 1
pqwriter = None
for i, df in enumerate(pd.read_csv(csv_filename, delimiter='_;_', chunksize=chunksize)):
#df = df.astype(str)
table = pa.Table.from_pandas(df=df)
# for the first chunk of records
if i == 0:
# create a parquet write object giving it an output file
pqwriter = pq.ParquetWriter(parquet_filename, table.schema, compression='gzip', use_dictionary=False)
pqwriter.write_table(table)
# close the parquet writer
if pqwriter:
pqwriter.close()
df = pd.read_parquet(parquet_filename)
print(df.memory_usage(deep=True))
Update 1:
I tried with fastparquet and I got 933kB in size.
for i, df in enumerate(pd.read_csv(csv_filename, delimiter='_;_', chunksize=chunksize)):
fastparquet.write(parquet_filename, df, compression='gzip', append=True)
Update 2:
The parameter chunksize have impact in file size. If larger, the size decreases. Using chunksize equal 30, the size was 76kB.