<jupyter_start><jupyter_text>Cuantas Publicaciones tiene cada Grupo de Investigacion<jupyter_code>df_grupos = pd.read_csv('grupos.csv',sep=',')
df_publicaciones = pd.read_csv('publicaciones.csv',sep=',')
data = pd.merge(df_grupos,df_publicaciones, how='inner', on='id_gi')
df = data.loc[:,['codigo_entidad', 'entidad','id_gi','nombre_gi','Publicaciones']]
df = df[["entidad", "nombre_gi", "Publicaciones"]]
def toNumbers(row):
    if(len(row) > 0):
        return 1

df['size'] = df.apply (lambda row: toNumbers(row), axis=1)
df.head(3)
df1 = df.groupby(['entidad', 'nombre_gi'])['size'].sum()
df1 = df1.reset_index()
# start a new flare.json document
d = dict()
d = {"name":"flare", "children": []}

for line in df1.values:
    the_parent = line[0]
    the_child = line[1]
    child_size = line[2]

    # make a list of keys
    keys_list = []
    for item in d['children']:
        keys_list.append(item['name'])

    # if 'the_parent' is NOT a key in the flare.json yet, append it
    if not the_parent in keys_list:
        d['children'].append({"name":the_parent, "children":[{"name":the_child, "size":child_size}]})

    # if 'the_parent' IS a key in the flare.json, add a new child to it
    else:
        d['children'][keys_list.index(the_parent)]['children'].append({"name":the_child, "size":child_size})


# export the final result to a json file
with open('flare.json', 'w') as outfile:
    json.dump(d, outfile)
!ls<jupyter_output>CSV2Flare.ipynb   flare.json        grupos.csv        publicaciones.csv
{'fraction_non_alphanumeric': 0.1690885072655218, 'fraction_numerical': 0.007926023778071334, 'mean_word_length': 4.489130434782608, 'pattern_counts': {'":': 8, '<': 4, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '646570', 'license': 'MIT', 'n_tokens_mistral': 563, 'n_tokens_neox': 551, 'n_words': 126, 'path': 'data/CSV2Flare.ipynb', 'repo_name': 'crishernandezmaps/pias-bubbles', 'size': '1514'}