generated from dataforgoodfr/d4g-project-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into scorreia/poc_analysis_notebook
- Loading branch information
Showing
17 changed files
with
634 additions
and
435 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import os | ||
import sqlite3 | ||
import tempfile | ||
from datetime import datetime | ||
|
||
import pandas as pd | ||
|
||
with tempfile.TemporaryDirectory() as temp_dir: | ||
os.chdir(temp_dir) | ||
|
||
os.system( | ||
"kaggle datasets download -d asaniczka/tmdb-movies-dataset-2023-930k-movies >&2", | ||
) | ||
os.system("unzip tmdb-movies-dataset-2023-930k-movies.zip >&2") | ||
|
||
df = pd.read_csv("TMDB_movie_dataset_v11.csv", parse_dates=["release_date"]) | ||
|
||
# Remove adult movies | ||
df = df[df["adult"] == False] # noqa: E712 | ||
|
||
# Remove documentaries | ||
df = df[df["genres"].str.contains("Documentary") == False] # noqa: E712 | ||
|
||
# Remove movies with a future release date | ||
now = datetime.now() | ||
df = df[df["release_date"] < now] | ||
|
||
# Remove movies with no known revenue | ||
# and original_language other than EU languages | ||
df = df[ | ||
(df["revenue"] == 0) | ||
& ( | ||
df["original_language"].isin( | ||
[ | ||
"cs", | ||
"da", | ||
"de", | ||
"en", | ||
"es", | ||
"et", | ||
"fi", | ||
"fr", | ||
"hr", | ||
"hu", | ||
"is", | ||
"it", | ||
"lt", | ||
"lv", | ||
"nl", | ||
"no", | ||
"pl", | ||
"pt", | ||
"ro", | ||
"sl", | ||
"sv", | ||
], | ||
) | ||
) | ||
| (df["revenue"] > 0) | ||
] | ||
|
||
# Add a column with the production_year based on the release_date | ||
df["production_year"] = df["release_date"].dt.year | ||
|
||
# Select the columns we want | ||
df = df[ | ||
[ | ||
"id", | ||
"title", | ||
"original_title", | ||
"production_year", | ||
"poster_path", | ||
] | ||
] | ||
|
||
# Set original title to blank string if same as title | ||
df["original_title"] = df["original_title"].where(df["title"] != df["original_title"], "") | ||
|
||
# Save the dataframe to a SQLite database | ||
with tempfile.NamedTemporaryFile(suffix=".sqlite", delete=False) as temp_file: | ||
temp_filename = temp_file.name | ||
with sqlite3.connect(temp_filename) as conn: | ||
df.to_sql("films", conn, index=False) | ||
|
||
# Print db file to stdout | ||
os.system(f"cat {temp_filename}") |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.