【发布时间】:2021-10-16 09:25:22
【问题描述】:
尝试将图像1转换为2,数据来自数据框。
【问题讨论】:
标签: graph formatting numbers plotly range
尝试将图像1转换为2,数据来自数据框。
【问题讨论】:
标签: graph formatting numbers plotly range
import numpy as np
import pandas as pd
import plotly.express as px
import re
df = pd.DataFrame({"orderNumber": [str(o) for o in range(1000, 1020)],
"Resolution in days": np.random.randint(1, 25, 20)})
px.bar(df, x="orderNumber", y="Resolution in days").show()
df["bin"] = pd.cut(df["Resolution in days"], bins=[0, 5, 10, 15, 20, 25])
px.bar(
df.groupby("bin", as_index=False).agg({"orderNumber": "count"}).assign(
bin=lambda d: d["bin"].apply(lambda s: "-".join(re.findall("[0-9]+", str(s))))),
x="bin",
y="orderNumber").show()
【讨论】: