-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathus_rel_doc.py
More file actions
29 lines (28 loc) · 892 Bytes
/
Copy pathus_rel_doc.py
File metadata and controls
29 lines (28 loc) · 892 Bytes
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
#Read-in script for U.S. related documents (post-2005 patents only)
# Importing necessary packages.
import os
import zipfile as zip
import pandas as pd
import csv
# Set up file path:
# Please include the folder path of the file you are reading. Ex: os.chdir("C:/Users/johnsmith/Downloads")
os.chdir("")
# Selecting the zip file.
file_name = "usreldoc.tsv.zip"
f_name = "usreldoc.tsv"
zf = zip.ZipFile(file_name)
# Reading the selected file in the zip.
chunksize = 10 ** 4
count = 1
n_obs = 0
final = []
for df in pd.read_csv(zf.open(f_name), delimiter="\t", chunksize=chunksize, quoting=csv.QUOTE_NONNUMERIC):
print('processing chunk: ' + str(count))
n_obs += len(df)
count += 1
final.append(df)
# Create data frame with all observations
df = pd.concat(final)
# Print summary of data: number of observations, columns, and each variable data type
print(n_obs)
print(df.dtypes)