Support colum renaming and make argument names clearer in df_to_type_list

This commit is contained in:
Maximilian Schmeller 2022-12-25 20:39:44 +09:00
parent 33f8c61c4a
commit 0662386732

View file

@ -6,11 +6,16 @@ def row_to_type(row, type, **type_kwargs):
return type(**row, **type_kwargs)
def df_to_type_list(df, type, mappers=None, **type_kwargs):
if mappers is not None:
for col, mapper in mappers.items():
def df_to_type_list(df, type, column_value_mappers=None, column_to_field_mappings=None, **type_kwargs):
if column_value_mappers is not None:
for col, mapper in column_value_mappers.items():
df[col] = df[col].map(mapper)
if column_to_field_mappings is not None:
for col, field in column_to_field_mappings.items():
df[field] = df[col]
del df[col]
has_idx = not isinstance(df.index, pd.RangeIndex)
ret_list = []