From b25b7a63d755d8412023d03daf0c47b4eaab2bb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Miller=20=28=E9=94=BA=E4=BF=8A=29?= Date: Mon, 12 Sep 2022 18:23:43 +0800 Subject: [PATCH] feat($pandas): multiple conditions filter --- python_boilerplate/demo/pandas_usage.py | 9 ++++++--- tests/demo/test_pandas_usage.py | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/python_boilerplate/demo/pandas_usage.py b/python_boilerplate/demo/pandas_usage.py index a261841..c9307c6 100644 --- a/python_boilerplate/demo/pandas_usage.py +++ b/python_boilerplate/demo/pandas_usage.py @@ -48,14 +48,17 @@ def look_for_sony_published_games() -> DataFrame: } dropped_columns = list(all_columns - selected_columns) sony_published: Final = video_games[ - video_games["Metadata.Publishers"] == "Sony" + (video_games["Metadata.Publishers"] == "Sony") + & (video_games["Features.Max Players"] > 1) + & (video_games["Title"].str.contains("t")) ].drop(columns=dropped_columns) release_year: Final = "Release.Year" sony_games_release_year: Final = sony_published[release_year] min_release_year = sony_games_release_year.sort_values().min() max_release_year = sony_games_release_year.sort_values().max() logger.info( - f"From {min_release_year} to {max_release_year}, Sony has published {len(sony_published)} games" + f"From {min_release_year} to {max_release_year}, Sony has published {len(sony_published)} games, " + f"those are multi-player, title with 't'" ) game_release_each_year: Final[Series] = ( sony_published.groupby(release_year)[release_year] @@ -119,4 +122,4 @@ def data_generation(): if __name__ == "__main__": - data_generation() + look_for_sony_published_games() diff --git a/tests/demo/test_pandas_usage.py b/tests/demo/test_pandas_usage.py index 8564f95..043dad6 100644 --- a/tests/demo/test_pandas_usage.py +++ b/tests/demo/test_pandas_usage.py @@ -58,7 +58,7 @@ def test_pandas_reading_csv() -> None: def test_look_for_sony_published_games(): sony_published_games = look_for_sony_published_games() assert sony_published_games is not None - assert len(sony_published_games) == 60 + assert len(sony_published_games) == 9 assert Path(sony_published_video_games_path).exists(), "CSV file NOT exists!"