-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql2.py
More file actions
184 lines (175 loc) · 5.42 KB
/
Copy pathsql2.py
File metadata and controls
184 lines (175 loc) · 5.42 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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import psycopg2 as pg2
import sys
#connect to database
con = None
con = pg2.connect("host='localhost' dbname='newsclusters' user='jake' password='passwordjake'")
cur = con.cursor()
#add authors table
query = '''
CREATE TABLE authors (junk varchar(10),
byline_person_0_firstname varchar(50),
byline_person_0_middlename varchar(50),
byline_person_0_lastname varchar(50),
author varchar(100),
author_id varchar(100),
topic_num_0 NUMERIC,
topic_num_1 NUMERIC,
topic_num_2 NUMERIC,
topic_num_3 NUMERIC,
topic_num_4 NUMERIC,
topic_num_5 NUMERIC,
topic_num_6 NUMERIC,
topic_num_7 NUMERIC,
topic_num_8 NUMERIC,
topic_num_9 NUMERIC,
topic_num_10 NUMERIC,
topic_num_11 NUMERIC,
topic_num_12 NUMERIC,
topic_num_13 NUMERIC,
topic_num_14 NUMERIC,
topic_num_15 NUMERIC,
topic_num_16 NUMERIC,
topic_num_17 NUMERIC,
topic_num_18 NUMERIC,
topic_num_19 NUMERIC,
topic_num_20 NUMERIC,
topic_num_21 NUMERIC,
topic_num_22 NUMERIC,
topic_num_23 NUMERIC,
topic_num_24 NUMERIC,
topic_num_25 NUMERIC,
topic_num_26 NUMERIC,
topic_num_27 NUMERIC,
topic_num_28 NUMERIC,
topic_num_29 NUMERIC,
topic_num_30 NUMERIC,
topic_num_31 NUMERIC,
topic_num_32 NUMERIC,
topic_num_33 NUMERIC,
total_articles NUMERIC,
topic_num_0_perc NUMERIC,
topic_num_1_perc NUMERIC,
topic_num_2_perc NUMERIC,
topic_num_3_perc NUMERIC,
topic_num_4_perc NUMERIC,
topic_num_5_perc NUMERIC,
topic_num_6_perc NUMERIC,
topic_num_7_perc NUMERIC,
topic_num_8_perc NUMERIC,
topic_num_9_perc NUMERIC,
topic_num_10_perc NUMERIC,
topic_num_11_perc NUMERIC,
topic_num_12_perc NUMERIC,
topic_num_13_perc NUMERIC,
topic_num_14_perc NUMERIC,
topic_num_15_perc NUMERIC,
topic_num_16_perc NUMERIC,
topic_num_17_perc NUMERIC,
topic_num_18_perc NUMERIC,
topic_num_19_perc NUMERIC,
topic_num_20_perc NUMERIC,
topic_num_21_perc NUMERIC,
topic_num_22_perc NUMERIC,
topic_num_23_perc NUMERIC,
topic_num_24_perc NUMERIC,
topic_num_25_perc NUMERIC,
topic_num_26_perc NUMERIC,
topic_num_27_perc NUMERIC,
topic_num_28_perc NUMERIC,
topic_num_29_perc NUMERIC,
topic_num_30_perc NUMERIC,
topic_num_31_perc NUMERIC,
topic_num_32_perc NUMERIC,
topic_num_33_perc NUMERIC,
dominant_topic_num NUMERIC,
dominant_topic_name VARCHAR(50)
);
'''
cur.execute(query)
con.commit()
#import data from csv
query = '''
COPY authors(junk,author_id,
byline_person_0_firstname,
byline_person_0_middlename,
byline_person_0_lastname,
author,
topic_num_0,
topic_num_1,
topic_num_2,
topic_num_3,
topic_num_4,
topic_num_5,
topic_num_6,
topic_num_7,
topic_num_8,
topic_num_9,
topic_num_10,
topic_num_11,
topic_num_12,
topic_num_13,
topic_num_14,
topic_num_15,
topic_num_16,
topic_num_17,
topic_num_18,
topic_num_19,
topic_num_20,
topic_num_21,
topic_num_22,
topic_num_23,
topic_num_24,
topic_num_25,
topic_num_26,
topic_num_27,
topic_num_28,
topic_num_29,
topic_num_30,
topic_num_31,
topic_num_32,
topic_num_33,
total_articles,
topic_num_0_perc,
topic_num_1_perc,
topic_num_2_perc,
topic_num_3_perc,
topic_num_4_perc,
topic_num_5_perc,
topic_num_6_perc,
topic_num_7_perc,
topic_num_8_perc,
topic_num_9_perc,
topic_num_10_perc,
topic_num_11_perc,
topic_num_12_perc,
topic_num_13_perc,
topic_num_14_perc,
topic_num_15_perc,
topic_num_16_perc,
topic_num_17_perc,
topic_num_18_perc,
topic_num_19_perc,
topic_num_20_perc,
topic_num_21_perc,
topic_num_22_perc,
topic_num_23_perc,
topic_num_24_perc,
topic_num_25_perc,
topic_num_26_perc,
topic_num_27_perc,
topic_num_28_perc,
topic_num_29_perc,
topic_num_30_perc,
topic_num_31_perc,
topic_num_32_perc,
topic_num_33_perc,
dominant_topic_num,
dominant_topic_name
)
FROM '/home/jake/data_science/capstones/NewsClusters/data/authors.csv'
DELIMITER ','
CSV HEADER;
'''
cur.execute(query)
con.commit()
con.close()