mirror of
https://github.com/qurator-spk/modstool.git
synced 2025-06-26 12:09:55 +02:00
🧹 Extract a function to convert list[dict] to a DataFrame
This commit is contained in:
parent
5c2dfa8505
commit
968572168e
2 changed files with 27 additions and 10 deletions
|
@ -14,7 +14,7 @@ import click
|
|||
import pandas as pd
|
||||
from tqdm import tqdm
|
||||
|
||||
from .lib import sorted_groupby, TagGroup, ns, flatten
|
||||
from .lib import sorted_groupby, TagGroup, ns, flatten, dicts_to_df
|
||||
|
||||
|
||||
|
||||
|
@ -404,14 +404,7 @@ def process(mets_files: List[str], output_file: str, output_csv: str, output_xls
|
|||
#import traceback; traceback.print_exc()
|
||||
|
||||
# Convert the mods_info List[Dict] to a pandas DataFrame
|
||||
columns = []
|
||||
for m in mods_info:
|
||||
for c in m.keys():
|
||||
if c not in columns:
|
||||
columns.append(c)
|
||||
data = [[m.get(c) for c in columns] for m in mods_info]
|
||||
index = [m['recordInfo_recordIdentifier'] for m in mods_info] # PPN
|
||||
mods_info_df = pd.DataFrame(data=data, index=index, columns=columns)
|
||||
mods_info_df = dicts_to_df(mods_info, index_column="recordInfo_recordIdentifier")
|
||||
|
||||
# Pickle the DataFrame
|
||||
logger.info('Writing DataFrame to {}'.format(output_file))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue