lisphilar / covid19-sir

CovsirPhy: Python library for COVID-19 analysis with phase-dependent SIR-derived ODE models.
https://lisphilar.github.io/covid19-sir/
Apache License 2.0
109 stars 43 forks source link

[New] DataEngineer class for data cleaning, transforming and complementing #1064

Closed lisphilar closed 1 year ago

lisphilar commented 2 years ago

Summary of this new feature

New class DataEngineer will be created for data cleaning, transforming and complementing. JHUData class and so on handles internaly at the current version, but it is required to improve transparency of these procedures.

CovsirPhy version: 2.24.0

lisphilar commented 2 years ago

1064:

DataEngineer class was created.

# Data preparation
import covsirphy as cs
loader = cs.DataLoader()
loader.jhu()
raw_df = loader.locked.copy()
# Set-up DataEngineer instance
engineer = DataEngineer(data=raw_df, layers=["ISO3", "Province"], date="Date")
# Data cleaning
engineer.clean(kind=["convert_date", "resample", "fillna"])
# Calculate daily new case
engineer.diff(column="Tests", suffix="_diff", freq="D")
# Data complement of S, F, R, Tests
col_dict = dict(population="Population", confirmed="Confirmed", fatal="Fatal", recovered="Recovered", tests="Tests")
procedures = engineer.complement_assess(address=["Japan", "Tokyo"], col_dict=col_dict)
engineer.complement_force(address=["Japan", "Tokyo"], procedures=procedures)
# Data transformation: calculate Susceptible, Infected, specifying column names
engineer.transform(new_dict={"susceptible": "Susceptible", "infected": "Infected"},  **col_dict)
# Get processed data (pandas.DataFrame)
engineer.all()
lisphilar commented 2 years ago

Codes of .complement_acess and .complement_force are from JHUDataComplementHandler and PCRData class. Tests of the new methods should be updated with some countries' data later. JHUDataComplementHandler class could be deprecated.

lisphilar commented 2 years ago

With #1090,

lisphilar commented 1 year ago

New documentation will be added to https://github.com/lisphilar/covid19-sir/tree/master/example