calculate Datum from Mont/Week
This commit is contained in:
1 parent
dff0c12c77
commit
286ea0252c
1 file changed
+26
-9
@@ -16,7 +16,8 @@ def interpolate_daily(df):
|
|||||||
.rename(columns={"index": "Datum"})
|
.rename(columns={"index": "Datum"})
|
||||||
)
|
)
|
||||||
|
|
||||||
def plot_percentiles(ax, x, data_dict, p_keys, colors=None, linewidths=None, labels=None, fill=True, fill_color="lightcoral", fill_alpha=0.25):
|
def plot_percentiles(ax, x, data_dict, p_keys, colors=None, linewidths=None, labels=None,
|
||||||
|
linestyle=None, fill=True, fill_color="lightcoral", fill_alpha=0.25):
|
||||||
"""
|
"""
|
||||||
Plot multiple percentile curves from a dictionary like who_head_daily.
|
Plot multiple percentile curves from a dictionary like who_head_daily.
|
||||||
|
|
||||||
@@ -46,7 +47,8 @@ def plot_percentiles(ax, x, data_dict, p_keys, colors=None, linewidths=None, lab
|
|||||||
data_dict[key][:n],
|
data_dict[key][:n],
|
||||||
color=colors[i],
|
color=colors[i],
|
||||||
linewidth=linewidths[i],
|
linewidth=linewidths[i],
|
||||||
label=labels[i]
|
label=labels[i],
|
||||||
|
linestyle=linestyle[i]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Fill between min and max percentile
|
# Fill between min and max percentile
|
||||||
@@ -91,17 +93,28 @@ who_head_df = pd.read_excel(
|
|||||||
sheet_name="WHO Kopfumfang",
|
sheet_name="WHO Kopfumfang",
|
||||||
engine="odf"
|
engine="odf"
|
||||||
)
|
)
|
||||||
|
def calculateDateFromBrithday(df, birthday ):
|
||||||
|
|
||||||
|
new_df = pd.DataFrame(columns=["Datum"])
|
||||||
|
for idx, (val1, val2) in enumerate(zip(df["Month"], df["Week"])):
|
||||||
|
if not pd.isna(val1):
|
||||||
|
new_df.loc[idx, "Datum"] = (birthday + pd.DateOffset(months=val1))
|
||||||
|
if not pd.isna(val2):
|
||||||
|
new_df.loc[idx, "Datum"] = (birthday + pd.DateOffset(weeks=val2))
|
||||||
|
|
||||||
|
return pd.to_datetime(new_df["Datum"], format="%d.%m.%Y", errors="coerce")
|
||||||
|
|
||||||
|
alina_df["Datum"] = pd.to_datetime(alina_df["Datum"],format="%d.%m.%Y",errors="coerce")
|
||||||
|
|
||||||
# Ensure Datum is datetime (safe to run even if already converted)
|
# Ensure Datum is datetime (safe to run even if already converted)
|
||||||
who_weight_df["Datum"] = pd.to_datetime(who_weight_df["Datum"],format="%d.%m.%Y",errors="coerce")
|
who_weight_df["Datum"] = calculateDateFromBrithday(who_weight_df,alina_df["Datum"][0] )
|
||||||
who_height_df["Datum"] = pd.to_datetime(who_height_df["Datum"],format="%d.%m.%Y",errors="coerce")
|
who_height_df["Datum"] = calculateDateFromBrithday(who_height_df,alina_df["Datum"][0] )
|
||||||
who_head_df["Datum"] = pd.to_datetime(who_weight_df["Datum"],format="%d.%m.%Y",errors="coerce")
|
who_head_df["Datum"] = calculateDateFromBrithday(who_head_df,alina_df["Datum"][0] )
|
||||||
|
|
||||||
who_weight_daily = interpolate_daily(who_weight_df)
|
who_weight_daily = interpolate_daily(who_weight_df)
|
||||||
who_height_daily = interpolate_daily(who_height_df)
|
who_height_daily = interpolate_daily(who_height_df)
|
||||||
who_head_daily = interpolate_daily(who_head_df)
|
who_head_daily = interpolate_daily(who_head_df)
|
||||||
|
|
||||||
alina_df["Datum"] = pd.to_datetime(alina_df["Datum"],format="%d.%m.%Y",errors="coerce")
|
|
||||||
|
|
||||||
# Plot
|
# Plot
|
||||||
last_alina_date = alina_df["Datum"].max() + pd.DateOffset(months=2)
|
last_alina_date = alina_df["Datum"].max() + pd.DateOffset(months=2)
|
||||||
@@ -118,6 +131,7 @@ percentile_list = ['P1', 'P3', 'P10', 'P25',
|
|||||||
colors_list = ["lightcoral" if p != "P50" else "darkred" for p in percentile_list]
|
colors_list = ["lightcoral" if p != "P50" else "darkred" for p in percentile_list]
|
||||||
linewidths_list = [1.5 if p != "P50" else 2.5 for p in percentile_list]
|
linewidths_list = [1.5 if p != "P50" else 2.5 for p in percentile_list]
|
||||||
label_list = [p if p == "P50" or p == "P3" or p == "P97" else "" for p in percentile_list]
|
label_list = [p if p == "P50" or p == "P3" or p == "P97" else "" for p in percentile_list]
|
||||||
|
linestyle_list = ["--" if p == "P3" or p == "P97" else "-" for p in percentile_list]
|
||||||
# ---------- 1. WEIGHT ----------
|
# ---------- 1. WEIGHT ----------
|
||||||
ax = axes[0]
|
ax = axes[0]
|
||||||
plot_percentiles(
|
plot_percentiles(
|
||||||
@@ -127,7 +141,8 @@ plot_percentiles(
|
|||||||
percentile_list,
|
percentile_list,
|
||||||
colors=colors_list,
|
colors=colors_list,
|
||||||
linewidths=linewidths_list,
|
linewidths=linewidths_list,
|
||||||
labels=label_list
|
labels=label_list,
|
||||||
|
linestyle=linestyle_list
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -166,7 +181,8 @@ plot_percentiles(
|
|||||||
percentile_list,
|
percentile_list,
|
||||||
colors=colors_list,
|
colors=colors_list,
|
||||||
linewidths=linewidths_list,
|
linewidths=linewidths_list,
|
||||||
labels=label_list
|
labels=label_list,
|
||||||
|
linestyle=linestyle_list
|
||||||
)
|
)
|
||||||
ax.plot(alina_df["Datum"], alina_df["Größe"],
|
ax.plot(alina_df["Datum"], alina_df["Größe"],
|
||||||
color="green", linewidth=1.5, marker="o")
|
color="green", linewidth=1.5, marker="o")
|
||||||
@@ -202,7 +218,8 @@ plot_percentiles(
|
|||||||
percentile_list,
|
percentile_list,
|
||||||
colors=colors_list,
|
colors=colors_list,
|
||||||
linewidths=linewidths_list,
|
linewidths=linewidths_list,
|
||||||
labels=label_list
|
labels=label_list,
|
||||||
|
linestyle=linestyle_list
|
||||||
)
|
)
|
||||||
|
|
||||||
ax.plot(alina_df["Datum"], alina_df["Kopfumfang"],
|
ax.plot(alina_df["Datum"], alina_df["Kopfumfang"],
|
||||||
|
|||||||
Reference in new issue
Block a user