refactoring

This commit is contained in:
frankknoll
2023-01-20 00:39:04 +01:00
parent ba826978c6
commit 380721392f
2 changed files with 11 additions and 10 deletions

View File

@@ -5,23 +5,24 @@ class SymptomsByBatchcodesTableFactory:
@staticmethod
def createSymptomsByBatchcodesTable(VAERSVAX, VAERSSYMPTOMS):
index_columns = ['VAX_LOT1', 'VAX_LOT2']
return pd.merge(
SymptomsByBatchcodesTableFactory._get_VAERSVAX_WITH_VAX_LOTS(VAERSVAX),
SymptomsByBatchcodesTableFactory._get_VAERSVAX_WITH_VAX_LOTS(VAERSVAX, index_columns),
SymptomsByBatchcodesTableFactory._getSymptomsTable(VAERSSYMPTOMS),
on = 'VAERS_ID').set_index(['VAX_LOT1', 'VAX_LOT2'])[['SYMPTOMS']]
on = 'VAERS_ID').set_index(index_columns)[['SYMPTOMS']]
@staticmethod
def _get_VAERSVAX_WITH_VAX_LOTS(VAERSVAX):
def _get_VAERSVAX_WITH_VAX_LOTS(VAERSVAX, index_columns):
return pd.concat(
[VAERSVAX, SymptomsByBatchcodesTableFactory._getVaxLotsTable(VAERSVAX)],
axis='columns').reset_index().drop_duplicates(subset=['VAERS_ID', 'VAX_LOT1', 'VAX_LOT2'])
[VAERSVAX, SymptomsByBatchcodesTableFactory._getVaxLotsTable(VAERSVAX, index_columns)],
axis='columns').reset_index().drop_duplicates(subset = ['VAERS_ID'] + index_columns)
@staticmethod
def _getVaxLotsTable(VAERSVAX):
def _getVaxLotsTable(VAERSVAX, index_columns):
VAX_LOT_LIST_Table = VAERSVAX.groupby("VAERS_ID").agg(VAX_LOT_LIST = pd.NamedAgg(column = 'VAX_LOT', aggfunc = list))
return pd.DataFrame(
[fill(VAX_LOTS, 2, str(np.nan)) for VAX_LOTS in VAX_LOT_LIST_Table['VAX_LOT_LIST'].tolist()],
columns = ['VAX_LOT1', 'VAX_LOT2'],
columns = index_columns,
index = VAX_LOT_LIST_Table.index)
@staticmethod