Моя группа по месяцам
отображает график с начала месяца,
который имеет значение продаж, равное нулю,
поскольку для этой даты нет записей.
Мне нужно, чтобы график отображался с даты первой записи в кадре данных.
И аналогично для последней даты в кадре данных.
df_monthly = (
df_output
.groupby([pd.Grouper(key='date', freq='MS'), 'region'])
.agg(
sales=('sales', 'sum'),
last_date=('date', 'max') # last actual date in the bucket
)
.reset_index()
)
fig1 = px.line(
df_monthly,
x="last_date", # ← use actual date instead of month start
y="sales",
color="region",
markers=True,
hover_data={
"last_date": "|%d %b %Y",
"sales": ":,.0f"
}
)
# ######################
# fig1.update_xaxes(range=["2018-02-06", "2022-02-14"])
# fig.update_xaxes(autorange=)
# fig1.update_xaxes(autorange=True)
# ####################### ABOVE line ###########
fig1.update_layout(xaxis=dict(range=['2018-02-06', '2022-02-14']))
Подробнее здесь: https://stackoverflow.com/questions/799 ... d-end-date