【问题标题】:Trying to change the number format while plotting plotly bar graph在绘制条形图时尝试更改数字格式
【发布时间】:2021-10-16 09:25:22
【问题描述】:

尝试将图像1转换为2,数据来自数据框。

【问题讨论】:

    标签: graph formatting numbers plotly range


    【解决方案1】:
    • 模拟了一个您在问题中没有提供的数据框
    • 已经从同一个数据框生成了两个图
    • 第二个图使用 cut 生成 bin,并重新格式化 bin 以匹配图像中的格式
    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()
    

    【讨论】:

      猜你喜欢
      • 2020-08-19
      • 1970-01-01
      • 1970-01-01
      • 2015-07-19
      • 2019-10-09
      • 1970-01-01
      • 1970-01-01
      • 2016-04-12
      相关资源
      最近更新 更多