<jupyter_start><jupyter_text>Political controlThis uses data from http://opencouncildata.co.uk/downloads.php to get the overal control and the current coalition for Uk councils, mapped against out groupings and leagues.<jupyter_code>cdf = pd.read_csv(Path("data", "source", "opencouncildata_councils.csv"))
cdf["name"] = cdf["name"].str.replace(" CC","").str.strip()
cdf = cdf.la.create_code_column(source_col="name")
cdf = cdf.set_index("local-authority-code")
cdf = cdf[["majority", "coalition"]]

# match for new Northamptonshire councils
adf = pd.DataFrame([["WNT", "CON", "CON"], ["NNT", "CON", "CON"]],
                   columns=["local-authority-code", "majority", "coaliton"]).set_index("local-authority-code")

cdf = pd.concat([cdf, adf])

df = (get_la_with_leagues()
      .set_index("local-authority-code")
      .join(cdf, how="outer")
      .reset_index())

df.pivot_table("local-authority-code", index="majority", columns="league-group", aggfunc="count").fillna(0)<jupyter_output><empty_output><jupyter_text>This source does not have information for combined authorities, and there's not many of them, so we'll ignore those.Similarly, given the low number of NI with plans, we'll ignore political control in NI. This means political control will be avaliable for 'County councils', 'District councils' and 'Single tier'.Reviewing the caolition information, there is too much information avalaible to put it in an easy drop down.<jupyter_code>mask = df["league-group"].isin(["County councils",
                               "District councils", "Single tier"])
df = df[mask]
df["majority"] = df["majority"].map({"CON": "Conservative",
                                     "IND": "Independent",
                                     "LAB": "Labour",
                                     "LD": "Liberal Democrat",
                                     "NOC": "Coalition/Minority",
                                     "PC": "Plaid Cymru"})

df.pivot_table("local-authority-code", index="majority",
               columns="league-group", aggfunc="count").fillna(0)

# export this data
df = df.rename(columns={"majority":"political_control"})
cols = ["local-authority-code","official-name", "league-group", "political_control"]
df[cols].to_csv(Path("data", "outputs", "political_control.csv"), index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1509594882729211, 'fraction_numerical': 0.0008528784648187633, 'mean_word_length': 3.573099415204678, 'pattern_counts': {'":': 7, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '404466', 'license': 'MIT', 'n_tokens_mistral': 759, 'n_tokens_neox': 702, 'n_words': 169, 'path': 'notebooks/political_control.ipynb', 'repo_name': 'mysociety/climate_league_filter_datasets', 'size': '2345'}