refactoring
This commit is contained in:
@@ -5,23 +5,24 @@ class SymptomsByBatchcodesTableFactory:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def createSymptomsByBatchcodesTable(VAERSVAX, VAERSSYMPTOMS):
|
def createSymptomsByBatchcodesTable(VAERSVAX, VAERSSYMPTOMS):
|
||||||
|
index_columns = ['VAX_LOT1', 'VAX_LOT2']
|
||||||
return pd.merge(
|
return pd.merge(
|
||||||
SymptomsByBatchcodesTableFactory._get_VAERSVAX_WITH_VAX_LOTS(VAERSVAX),
|
SymptomsByBatchcodesTableFactory._get_VAERSVAX_WITH_VAX_LOTS(VAERSVAX, index_columns),
|
||||||
SymptomsByBatchcodesTableFactory._getSymptomsTable(VAERSSYMPTOMS),
|
SymptomsByBatchcodesTableFactory._getSymptomsTable(VAERSSYMPTOMS),
|
||||||
on = 'VAERS_ID').set_index(['VAX_LOT1', 'VAX_LOT2'])[['SYMPTOMS']]
|
on = 'VAERS_ID').set_index(index_columns)[['SYMPTOMS']]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_VAERSVAX_WITH_VAX_LOTS(VAERSVAX):
|
def _get_VAERSVAX_WITH_VAX_LOTS(VAERSVAX, index_columns):
|
||||||
return pd.concat(
|
return pd.concat(
|
||||||
[VAERSVAX, SymptomsByBatchcodesTableFactory._getVaxLotsTable(VAERSVAX)],
|
[VAERSVAX, SymptomsByBatchcodesTableFactory._getVaxLotsTable(VAERSVAX, index_columns)],
|
||||||
axis='columns').reset_index().drop_duplicates(subset=['VAERS_ID', 'VAX_LOT1', 'VAX_LOT2'])
|
axis='columns').reset_index().drop_duplicates(subset = ['VAERS_ID'] + index_columns)
|
||||||
|
|
||||||
@staticmethod
|
@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))
|
VAX_LOT_LIST_Table = VAERSVAX.groupby("VAERS_ID").agg(VAX_LOT_LIST = pd.NamedAgg(column = 'VAX_LOT', aggfunc = list))
|
||||||
return pd.DataFrame(
|
return pd.DataFrame(
|
||||||
[fill(VAX_LOTS, 2, str(np.nan)) for VAX_LOTS in VAX_LOT_LIST_Table['VAX_LOT_LIST'].tolist()],
|
[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)
|
index = VAX_LOT_LIST_Table.index)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user