-
Notifications
You must be signed in to change notification settings - Fork 0
/
feather_build.py
73 lines (65 loc) · 1.71 KB
/
feather_build.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# %%
# not working yet.
import pandas as pd
import numpy as np
import os
# %%
os.makedirs("feather/collection")
os.makedirs("feather/checkouts")
# %%
# column types
# both say that BibNum is int but I used str
# https://data.seattle.gov/Community/Library-Collection-Inventory/6vkj-f5xf
collection_cols = {
'BibNum': str,
'Title': str,
'Author': str,
'ISBN': str,
'PublicationYear': str,
'Publisher': str,
'Subjects': str,
'ItemType': str,
'ItemCollection': str,
'FloatingItem': str,
'ItemLocation': str,
'ReportDate': str,
'ItemCount': int
}
# https://data.seattle.gov/Community/Checkouts-By-Title-Physical-Items-/5src-czff
checkouts_cols = {
'ID': str,
'CheckoutYear': str,
'BibNumber': str,
'ItemBarcode': str,
'ItemType': str,
'Collection': str,
'CallNumber': str,
'ItemTitle': str,
'Subjects': str,
'CheckoutDateTime': str,
}
# %%
# collection
chunksize = 750000 # how many rows to read/write at a time.
count = 0
for df in pd.read_csv(
'library/Library_Collection_Inventory.csv',
chunksize=chunksize, dtype=collection_cols,
parse_dates=['ReportDate'],
iterator=True):
count += 1
df.reset_index().to_feather('feather/collection/file_{}.feather'.format(count),
compression = "lz4")
# %%
# checkouts
chunksize = 2000000 # how many rows to read/write at a time.
count = 0
for df in pd.read_csv(
'library/Checkouts_By_Title__Physical_Items_.csv',
chunksize=chunksize, dtype=checkouts_cols,
parse_dates=['CheckoutDateTime'],
iterator=True):
count += 1
df.reset_index().to_feather('feather/checkouts/file_{}.feather'.format(count),
compression = "lz4")
# %%