Skip to content

Commit

Permalink
Formatted with black
Browse files Browse the repository at this point in the history
  • Loading branch information
Re-st authored and github-actions[bot] committed Nov 24, 2023
1 parent ebb830d commit 221da39
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions analysis/age/hist_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@ def cluster_data(method, n_clst, df):
df["cluster_label"] = kmeans.labels_
elif method == "equal":
bins = [-np.inf] + quantiles + [np.inf]
df["cluster_label"] = pd.cut(df["age"], bins=bins, labels=False, include_lowest=True)
df["cluster_label"] = pd.cut(
df["age"], bins=bins, labels=False, include_lowest=True
)
print(quantiles)
print(unique_q_idx)
df["cluster_label"] = df["cluster_label"].apply(lambda x: unique_q_idx[x])
max_num = df["cluster_label"].max()
if max_num != n_clst - 1:
df["cluster_label"] = df["cluster_label"].apply(lambda x: n_clst - 1 if x == max_num else x)
df["cluster_label"] = df["cluster_label"].apply(
lambda x: n_clst - 1 if x == max_num else x
)

return df

Expand Down Expand Up @@ -271,7 +275,9 @@ def cluster(df, year, n_clst, method, cluster_by, outdir, font_name, folder_name
"minAge": int(age),
"maxAge": int(age) + 1,
"count": df_clst[df_clst["age"] == age].shape[0],
"ageGroup": int(df_clst.loc[df_clst["age"] == age].iloc[0]["cluster_label"])
"ageGroup": int(
df_clst.loc[df_clst["age"] == age].iloc[0]["cluster_label"]
),
}
for age in df_clst["age"].unique()
]
Expand Down

0 comments on commit 221da39

Please sign in to comment.