<jupyter_start><jupyter_text>Prepare Male and Female Names from GenderComputer  1. Prepare Unique Male and Female NamesThis data is used to obtain 2 csv files:* **a list of unique male names**, saved as `../male_names_only.csv` : a list of male names such that for each male name, it doesn't exist as a female name in any country* **a list of unique female names**, saved as `../female_names_only.csv` : a list of female names such that for each female name, it doesn't exist as a male name in any country<jupyter_code>from genderComputer import GenderComputer
gc = GenderComputer()

name_to_gender = {}
for country in gc.nameLists.keys():
    for gender, names in gc.nameLists[country].items():
        for name in names:
            if name in name_to_gender and  name_to_gender[name] != gender:
                name_to_gender[name] = 'invalid'
            else:
                name_to_gender[name] = gender
                
result = [(name, gender) for name, gender in name_to_gender.items() if gender != 'invalid']
# result
male_name = [name for name, gender in name_to_gender.items() if gender == 'male']
len(male_name)
female_name = [ name for name, gender in name_to_gender.items() if gender == 'female']
len(female_name)
import pandas as pd
# male_name
dfm = pd.DataFrame(data={"name": male_name})
dfm<jupyter_output><empty_output><jupyter_text>Check the name<jupyter_code>"palona" in dfm["name"].tolist()
"danyar" in dfm["name"].tolist()
dff = pd.DataFrame(data={"name": female_name})
dff<jupyter_output><empty_output><jupyter_text>Check the name<jupyter_code>"sveya" in dff["name"].tolist()<jupyter_output><empty_output><jupyter_text>Save the names into csv files<jupyter_code>dfm.to_csv("../male_names_only.csv", index=False)
dff.to_csv("../female_names_only.csv", index=False)<jupyter_output><empty_output><jupyter_text>2. Get Unique Name by CountryThis data is used to obtain 2 csv files:* **a list of unique male names that is unique for each country**, saved as `../unique_male_names_and_country.csv` : a list of male names such that (1) for each male name it doesn't exist as a female name in any country and (2) for each male name, it's unique for each country* **a list of unique female names that is unique for each country**, saved as `../unique_female_names_and_country.csv` : a list of female names such that (1) for each female name, it doesn't exist as a male name in any country  and (2) for each female name, it's unique for each country<jupyter_code>name_to_country = {}
for country in gc.nameLists.keys():
    for gender, names in gc.nameLists[country].items():
        for name in names:
            if name in name_to_country and  name_to_country[name] != country:
                name_to_country[name] = 'invalid'
            else:
                name_to_country[name] = country
                
result = [(name, country) for name, country in name_to_country.items() if country != 'invalid']
df = pd.DataFrame(data=result, columns=["name", "country"])
df
df.to_csv("../unique_name_country.csv", index=None)
df = pd.read_csv("../unique_name_country.csv")

# gcm = pd.read_csv("../../data/gc_name/male_names_only.csv")
gcm = pd.read_csv("../male_names_only.csv")
gcm = gcm.sample(frac=1, random_state=123)
mnames = gcm["name"].tolist()# # names from GC
# gcf = pd.read_csv("../../data/gc_name/female_names_only.csv")
gcf = pd.read_csv("../female_names_only.csv")
gcf = gcf.sample(frac=1, random_state=123)
fnames = gcf["name"].tolist()# # names from GC


df = df.sample(frac=1, random_state=12345)
n = 1
gb = df.groupby("country")
unique_male_names = []
unique_female_names = []
countries = []
for k in gb.groups.keys() :
    d = gb.get_group(k)
    male = ""
    female = ""
#     print(len(d["name"].tolist()))
#     print(d["name"].tolist()[0])
    for name in d["name"].tolist():
#         if "-" not in name and " " not in name and "\\" not in name:
        if male == "" :
            if name in mnames :
                male = name
        if female == "" :
            if name in fnames :
                female = name
        if male != "" and female != "" :
            unique_male_names.append(male.title())
            unique_female_names.append(female.title())
            countries.append(k)
            break
print(unique_male_names)
df_unique_male_names = pd.DataFrame(data={"name": unique_male_names, "country": countries})
df_unique_male_names.to_csv("../unique_male_names_and_country.csv")
df_unique_male_names 
df_unique_female_names = pd.DataFrame(data={"name": unique_female_names, "country": countries})
df_unique_female_names.to_csv("../unique_female_names_and_country.csv")
df_unique_female_names<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1270824434002563, 'fraction_numerical': 0.0051260145237078175, 'mean_word_length': 3.827835051546392, 'pattern_counts': {'":': 6, '<': 21, '<?xml version=': 0, '>': 21, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '295062', 'license': 'Apache-2.0', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1502, 'n_words': 432, 'path': 'codes/bias_rv/asset/gender_computer/genderComputer/prepare_male_female_names.ipynb', 'repo_name': 'yangzhou6666/BiasHeal', 'size': '4682'}