-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathchunking.py
More file actions
47 lines (43 loc) · 1.18 KB
/
Copy pathchunking.py
File metadata and controls
47 lines (43 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import pyarrow as pa
import pyarrow.parquet as pq
import pandas as pd
table_chunks = pd.read_csv(
"../../07-pandas/sec1-intro/yellow_tripdata_2020-01.csv.gz",
chunksize=1000000
)
print(type(table_chunks))
for chunk in table_chunks:
print(type(chunk))
print(chunk.shape)
table_chunks = pd.read_csv(
"../../07-pandas/sec1-intro/yellow_tripdata_2020-01.csv.gz",
chunksize=1000000,
dtype={
"VendorID": float, # We need to type
"passenger_count": float,
"RatecodeID": float,
"PULocationID": float,
"DOLocationID": float,
"payment_type": float,
}
) # we need to reopen again
first = True
writer = None
for chunk in table_chunks:
chunk_table = pa.Table.from_pandas(chunk)
schema = chunk_table.schema
if first:
first = False
writer = pq.ParquetWriter("output.parquet", schema=schema)
writer.write_table(chunk_table)
writer.close()
pf = pq.ParquetFile("output.parquet")
pf.metadata
pf.num_row_groups
for groupi in range(pf.num_row_groups):
group = pf.read_row_group(groupi)
print(type(group), len(group))
break
table = pf.read()
len(table)
table = pq.read_table("output.parquet")