refactoring

This commit is contained in:
frankknoll
2023-01-20 01:18:05 +01:00
parent a954971e34
commit ee717367c9

View File

@@ -30,7 +30,10 @@ class SymptomsByBatchcodesTableFactory:
def _getVaxLotsTable(VAERSVAX, index_columns): 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, len(index_columns), str(np.nan)) for VAX_LOTS in VAX_LOT_LIST_Table['VAX_LOT_LIST'].tolist()], fillLsts(
lsts = VAX_LOT_LIST_Table['VAX_LOT_LIST'].tolist(),
desiredLen = len(index_columns),
fillValue = str(np.nan)),
columns = index_columns, columns = index_columns,
index = VAX_LOT_LIST_Table.index) index = VAX_LOT_LIST_Table.index)
@@ -45,5 +48,8 @@ class SymptomsByBatchcodesTableFactory:
VAERSSYMPTOMS['SYMPTOM5'] VAERSSYMPTOMS['SYMPTOM5']
]).dropna().to_frame(name = symptomsColumn).reset_index() ]).dropna().to_frame(name = symptomsColumn).reset_index()
def fill(lst, desiredLen, fillValue): def fillLsts(lsts, desiredLen, fillValue):
return [fillLst(lst, desiredLen, fillValue) for lst in lsts]
def fillLst(lst, desiredLen, fillValue):
return lst + [fillValue] * (max(desiredLen - len(lst), 0)) return lst + [fillValue] * (max(desiredLen - len(lst), 0))