Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit e8fd1fb6 authored by Samuël Weber's avatar Samuël Weber
Browse files

better daily mean

parent c669e59f
......@@ -384,6 +384,15 @@ def plot_ts(df, station, var, groupby, daily_mean):
:daily_mean: bool
:returns: a list of plotly traces
"""
def _group_by_day(df_orig, var):
df = df_orig.copy()
df["Date"] = pd.to_datetime(df["Date"])
df = df.set_index("Date")\
.groupby(pd.Grouper(freq="D"))\
.mean()\
.reset_index()
return df[["Date", var]].dropna()
traces=[]
if len(groupby) != 0:
for v in var:
......@@ -392,24 +401,27 @@ def plot_ts(df, station, var, groupby, daily_mean):
if all(dfgroup.loc[:, v].isnull()):
continue
if daily_mean:
dfgroup["Date"] = pd.to_datetime(dfgroup["Date"])
dfgroup = dfgroup.set_index("Date").groupby(pd.Grouper(freq="D")).mean().reset_index()
dfgroup = dfgroup.sort_values(by="Date")
dfplot = _group_by_day(dfgroup, v)
else:
dfplot = dfgroup.copy()
dfplot = dfplot.sort_values(by="Date")
traces.append(go.Scatter(
x=dfgroup.loc[:, "Date"],
y=dfgroup.loc[:, v],
x=dfplot.loc[:, "Date"],
y=dfplot.loc[:, v],
mode="lines+markers",
name="{}-{}-({})".format(station, v, groupName)
))
else:
for v in var:
if daily_mean:
dfgroup["Date"] = pd.to_datetime(dfgroup["Date"])
dfgroup = dfgroup.set_index("Date").groupby(pd.Grouper(freq="D")).mean().reset_index()
dfgroup = df.sort_values(by="Date")
dfplot = _group_by_day(df, v)
else:
dfplot = df.copy()
dfplot = dfplot.sort_values(by="Date").dropna()
print(dfplot)
traces.append(go.Scatter(
x=dfgroup.loc[:, "Date"],
y=dfgroup.loc[:, v],
x=dfplot.loc[:, "Date"],
y=dfplot.loc[:, v],
mode="lines+markers",
name="{}-{}".format(station, v)
))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment