【问题标题】:How to plot data from csv using Dash Plotly and Pandas如何使用 Dash Plotly 和 Pandas 从 csv 中绘制数据
【发布时间】:2019-02-13 03:03:39
【问题描述】:

在一个有四张工作表的 excel 电子表格中(这是一个 A/B 测试,工作表 1 是 a_group_flights,工作表 2 是 b_group_flights,工作表 3 是 a_group_hotels,工作表 4 是 b_group_hotels),我有兴趣绘制其中的两列“budget_price”和“total_spend”在“budget_datetime”显示的时间段内,并让这两条线(budget_price 和 total_spend)重叠,以显示您的预算与您实际在旅行上花费的金额之间的差异。

这是电子表格的样子: https://ibb.co/JHCf12z

我正在使用 Dash Plotly 并想用 Pandas 读取 excel 电子表格,然后将数据绘制在图表上。

xlsx = pd.ExcelFile('data.xlsx')

【问题讨论】:

    标签: python pandas csv plotly-dash


    【解决方案1】:

    代替阅读 excel
    xlsx = pd.read_excel('your_excel_file.xls') 
    
    

    要制作简单的线图,只需制作

    df = xlsx
    data = [go.Scatter( x=df['X_axis_column'], y=df['first_y_data', 'second_y_data'] )]
    

    如果你的 excel 有多个工作表,只需制作

    df1 = pd.read_excel('exel_file.xls', 'Sheet1')
    df2 = pd.read_excel('exel_file.xls', 'Sheet2')
    
    

    那你应该检查here看看你想要什么样的情节

    【讨论】:

    • 如何创建基本折线图(两条线,budget_price 列和 total_spend 列)与时间(budget_datetime 列)的关系?
    • 另外,您将如何使用 Pandas 遍历 excel 文件中的每个工作表?
    • 我将添加第一部分作为答案的编辑,还不确定第二部分,让我们找出来
    • Dash 的 app.layout 中会不会添加简单的线图代码?
    • 你需要看看这个,然后dash.plot.ly/getting-started
    猜你喜欢
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 2017-07-11
    • 2021-05-03
    • 1970-01-01
    • 1970-01-01
    • 2013-09-12
    • 1970-01-01
    相关资源
    最近更新 更多