-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest1.py
More file actions
29 lines (19 loc) · 704 Bytes
/
test1.py
File metadata and controls
29 lines (19 loc) · 704 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
import psycopg2 as pg
import pandas as pd
def get_data():
df = pd.DataFrame()
conn = pg.connect(host="localhost",database="cookpad",user="cookpad",password="password",port=5439)
cur = conn.cursor()
query = '''SELECT user_id,STRING_AGG (a.page_name,' -> ' ORDER BY a.log_time) path FROM public.pv_log a group by user_id'''
print(query)
cur.execute(query)
records = cur.fetchall()
for row in records:
df2 = {'user_id': row[0], 'path': row[1]}
df = df.append(df2, ignore_index = True)
# print(df)
df.to_csv("records.csv")
cur.close()
conn.close()
if __name__=='__main__':
get_data()