Skip to content

Commit

Permalink
feat($pandas): multiple conditions filter
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed Sep 12, 2022
1 parent 5a0177b commit b25b7a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions python_boilerplate/demo/pandas_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -119,4 +122,4 @@ def data_generation():


if __name__ == "__main__":
data_generation()
look_for_sony_published_games()
2 changes: 1 addition & 1 deletion tests/demo/test_pandas_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!"


Expand Down

0 comments on commit b25b7a6

Please sign in to comment.