<jupyter_start><jupyter_text>Adding Settings to NormalizeIn this notebook, the feature update to add the switch of whether or not to expand lists and dicts is tested.  Imports<jupyter_code>import os
import sys
sys.path.insert(0, os.pardir)
import pandas as pd
from flat_table import mapper, normalize<jupyter_output><empty_output><jupyter_text>Sample Dataframe<jupyter_code>data = [
    (
        1001, 
        { 'first_name': 'john', 'last_name': 'smith', 'phones': {'mobile': '201-..', 'home': '978-..'} },
        ['a', 'b'],
        [{ 'zip': '07014', 'city': 'clifton' }],
        { 'membership': True, 'memberid': '1231' }
    ),
    (
        1002, 
        pd.np.nan, 
        ['one', 'two', 'three', 'four'],
        [{'zip': '07014', 'address1': '1 Journal Square'}],
        { 'membership': False, 'memberid': '' }
    ),
    (
        1003, 
        { 'first_name': 'marry', 'last_name': 'kate', 'gender': 'female' }, 
        ['w', 'y', 'z'],
        [{ 'zip': '10001', 'city': 'new york' }, { 'zip': '10008', 'city': 'brooklyn' }],
        { 'membership': True, 'memberid': '9754' }
    ),
]
df = pd.DataFrame(data, columns=['id', 'user_info', 'name_list', 'address', 'membership'])
df.head()<jupyter_output><empty_output><jupyter_text>Setttings<jupyter_code>mp = mapper(df)
mp<jupyter_output><empty_output><jupyter_text>Find Original Df<jupyter_code>org_df = mp[mp.parent == '.']
org_df<jupyter_output><empty_output><jupyter_text>Settings<jupyter_code>expand_dicts = False
expand_lists = False

if expand_dicts and expand_lists:
    dataframe = mp[(mp.type != 'dict') & (mp.type != 'list')]
# dicts expand, lists are same
elif expand_dicts and not expand_lists:
    print('dict True list False')
    org_df = mp[mp.parent == '.']
    dict_items = org_df[org_df.type == 'dict'].child
    final_dict_items = mp[mp.parent.isin(dict_items)]
    final_others = org_df[org_df.type != 'dict']
    dataframe = pd.concat([final_dict_items, final_others]).sort_index()
# dicts are same, lists expand
elif not expand_dicts and expand_lists:
    print('dict False list True')
    org_df = mp[mp.parent == '.']
    list_items = mp[mp.type == 'list'].child
    final_list_items = mp[
        (mp.parent.isin(list_items) | mp.child.isin(list_items)) 
        & ~mp.type.isin(['dict', 'list'])]
    final_others = org_df[org_df.type != 'list']
    dataframe = pd.concat([final_list_items, final_others]).sort_index()
# original df
else:
    dataframe = mp[mp.parent == '.']
dataframe<jupyter_output><empty_output><jupyter_text>After Implementation<jupyter_code>normalize(df, expand_dicts=True, expand_lists=False)
normalize(df, expand_dicts=False, expand_lists=True)<jupyter_output>dict False list True
{'fraction_non_alphanumeric': 0.17061435973353073, 'fraction_numerical': 0.018134715025906734, 'mean_word_length': 4.138783269961977, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '113371', 'license': 'MIT', 'n_tokens_mistral': 1015, 'n_tokens_neox': 971, 'n_words': 197, 'path': 'notebooks/Feature Update - Setting Expand Options.ipynb', 'repo_name': 'gfmartins/flat_table', 'size': '2702'}