<jupyter_start><jupyter_text>Prepare townships Haute-Garonne  Imports<jupyter_code>%run "../config/notebook.ipynb"
%run "../config/files.ipynb"
%run "../utils/stop_execution.ipynb"

import pandas as pd<jupyter_output><empty_output><jupyter_text>Read from cache<jupyter_code>if 'FROM_CACHE' in locals() or 'FROM_CACHE' in globals():
    if FROM_CACHE:
        df_hautegaronne_townships = pd.read_csv(PREPARED_HAUTEGARONNE_TOWNSHIPS_FILE_PATH, index_col='code_insee')
        print("(from cache) df_hautegaronne_townships: {} townships entries".format(len(df_hautegaronne_townships.index)))        
        raise StopExecution<jupyter_output><empty_output><jupyter_text>Create the townships dataframe   Read the townships csv file<jupyter_code># df_communes = pd.read_excel(COMMUNES_STATISTICS_FILE_PATH, skiprows=3, header=1)
df_townships = pd.read_csv(TOWNSHIPS_LIST_FILE_PATH, sep=';')<jupyter_output><empty_output><jupyter_text>Row filter on department<jupyter_code>def is_hautegaronne(postalcode):
    spostalcode = str(postalcode)
    return (len(spostalcode) == 5) & (spostalcode[:2] == '31')
        
# df_communes_haute_garonne = df_communes[df_communes['Département'] == '31']
df_hautegaronne_townships = df_townships[list(df_townships['Code_postal'].apply(is_hautegaronne))]<jupyter_output><empty_output><jupyter_text>Filter kept columns<jupyter_code>df_hautegaronne_townships = df_hautegaronne_townships[['Code_commune_INSEE', 'Nom_commune']]
df_hautegaronne_townships.columns = ['code_insee', 'name']
df_hautegaronne_townships = df_hautegaronne_townships.set_index('code_insee')
df_hautegaronne_townships.drop_duplicates(keep = False, inplace = True)<jupyter_output><empty_output><jupyter_text>Persist<jupyter_code>df_hautegaronne_townships.to_csv(PREPARED_HAUTEGARONNE_TOWNSHIPS_FILE_PATH)
print("df_hautegaronne_townships: {} townships entries".format(len(df_hautegaronne_townships.index)))<jupyter_output>df_hautegaronne_townships: 578 townships entries
{'fraction_non_alphanumeric': 0.11082867310625318, 'fraction_numerical': 0.005592272496187087, 'mean_word_length': 9.524064171122994, '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': '629201', 'license': 'MIT', 'n_tokens_mistral': 776, 'n_tokens_neox': 765, 'n_words': 84, 'path': 'notebooks/prepare/prepare_townships_hautegaronne.ipynb', 'repo_name': 'laurentgrenier/maps_hautegaronne', 'size': '1967'}