-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopulate.py
More file actions
61 lines (41 loc) · 1.8 KB
/
Copy pathpopulate.py
File metadata and controls
61 lines (41 loc) · 1.8 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
import datetime
import pandas as pd
import numpy as np
import psycopg2
from db import *
from db import *
from project import *
from helpers import convert_date_to_postgres
# Make sure all tables have been created first
# Insert films
insert_ratings(list_of_ratings)
populate_films(films)
print ("films have been inserted.")
# Insert companies
list_company_na = company.dropna() # Drop all NaN(empty cells)
list_of_companies = list_company_na.drop_duplicates() # Drop all the duplicate rows in the dataframe
list_of_companies = list_of_companies.values.tolist() # Convert the list numpy array to a Python List
insert_companies(list_of_companies)
print ("companies have been inserted.")
# Insert Genres
list_of_genres = genre.drop_duplicates() # Drop all the duplicate rows in the dataframe
list_of_genres = list_of_genres.values.tolist() # Convert the list numpy array to a Python List
insert_genres(list_of_genres)
print ("Genres have been inserted.")
# Insert film Company relations
film_company = df2["company"].values.tolist() # Create a list of all the companies in the movies table
insert_film_company(film_company) # Insert all the film company relations
print ("film-company has been inserted.")
# Insert film Genre relations
film_genre = df2["genre"].values.tolist() # Create a list of all the genre's in the movies table
insert_film_genre(film_genre) # Insert all the film genre relations
print ("film-genre has been inserted.")
# Insert Persons and their film relationships
insert_persons(all_people)
print ("people have been inserted")
# Insert the relationships between films and people
insert_film_persons(film_writers, "writer");
insert_film_persons(directors, "director")
print ("writers and directors have been inserted")
insert_film_persons(stars, "star")
print ("All relationships have been inserted")