client_v2 = #connect to the OpenReview Client (API2) with your credentials
from collections.abc import MutableMapping
list_of_profile_ids = []
profile_list = openreview.tools.get_profiles(client_v2,list_of_profile_ids)
def flatten_dict(d, parent_key='', sep='_'):
"""
Recursively flattens a dictionary, concatenating nested keys.
"""
items = []
for k, v in d.items():
new_key = f"{parent_key}{sep}{k}" if parent_key else k
if isinstance(v, MutableMapping):
items.extend(flatten_dict(v, new_key, sep=sep).items())
elif isinstance(v, list):
for i, elem in enumerate(v):
# Handle lists of dictionaries by adding an index
if isinstance(elem, MutableMapping):
items.extend(flatten_dict(elem, f"{new_key}_{i}", sep=sep).items())
else:
# Just add the element if it's not a dictionary
items.append((f"{new_key}_{i}", elem))
else:
items.append((new_key, v))
return dict(items)
def extract_content(d):
flattened = flatten_dict(d.content)
content = {k: v for k, v in flattened.items()}
content['profile_id'] =d.id
return(content)
#Create a DataFrame with the flattened profile content + profile ID
profile_df = pd.DataFrame([extract_content(note) for note in profile_list)
#extract the columns you want included in the data
relevant_columns = ['profile_id'] + [c for c in profile_df.columns if 'history_0' in c]
profile_df_subset = profile_df[relevant_columns]