-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
52 lines (40 loc) · 1.28 KB
/
Copy pathmain.py
File metadata and controls
52 lines (40 loc) · 1.28 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
"""
This file contains the main function.
Launch the program with the following command: `python main.py`
"""
import pandas as pd
from etl.etl import ETL
def main() -> bool:
"""
Main function.
"""
data_folder = input("Enter the path to the data folder: ")
if_exists = input("Do you want to overwrite the existing data? (y/[n]): ")
return ETL().run(data_folder, if_exists)
def get_journal_which_quotes_the_most_amount_of_drugs(
data: pd.DataFrame,
) -> tuple[str, int]:
"""
Get the journal which quotes the most amount of drugs.
Parameters
----------
data : pd.DataFrame
The data.json file into a pandas DataFrame.
Returns
-------
tuple[str, int]
The journal name and the amount of drugs.
"""
ranking = data.groupby("journal").count()["drug"].sort_values(ascending=False)
return ranking.index[0], ranking.values[0]
if __name__ == "__main__":
if main():
print("ETL completed successfully.")
most_prolific_journal, nb_of_drugs = (
get_journal_which_quotes_the_most_amount_of_drugs(pd.read_json("data.json"))
)
print(
'The journal which quotes the most amount of drugs is "{}" with {} different drugs.'.format(
most_prolific_journal, nb_of_drugs
)
)