Python Forum
Plot Pandas DataFrame using Dash
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Plot Pandas DataFrame using Dash
#1
I have created Pandas DataFrame like this
import plotly
    import pandas as pd
    import cufflinks as cf
    plotly.offline.init_notebook_mode(connected=True)

    all_data = [('2018-04-08', '10:10:11', ['s1',10],['s2',15],['s3',5]),
                ('2018-04-08', '10:20:11', ['s4',8], ['s2',20],['s1',10]),
                ('2018-04-10', '10:30:11', ['s4',10],['s5',6], ['s6',3]), 
                ('2018-04-15', '10:18:11', ['s1',10],['s2',15],['s3',5]), 
                ]

    df = pd.DataFrame(all_data, columns = list("ABCDE"))
    df["day/time"] = pd.to_datetime(df["A"] + " "+ df["B"])
    df = df.melt(id_vars = ["day/time"], value_vars = ["C", "D", "E"])
    df[["category", "val"]] = pd.DataFrame(df.value.values.tolist(), index = df.index)
    df = df.pivot(index = "day/time", columns = "category", values = "val")
    fig = df.iplot(kind='bar', barmode='stack', asFigure=True)
    df['sum'] = df[list(df.columns)].sum(axis=1)
    df.to_csv('out1.csv')
    print (df)
The dataframe is printed as :
    category               s1    s2   s3    s4   s5   s6   sum
    day/time                                                  
    2018-04-08 10:10:11  10.0  15.0  5.0   NaN  NaN  NaN  30.0
    2018-04-08 10:20:11  10.0  20.0  NaN   8.0  NaN  NaN  38.0
    2018-04-10 10:30:11   NaN   NaN  NaN  10.0  6.0  3.0  19.0
    2018-04-15 10:18:11  10.0  15.0  5.0   NaN  NaN  NaN  30.0
But I want to plot it in the following way.

X-axis will have time .Y axis Initially will only show sum but will have a drop down and on click will show the values in the data frame(With a different color code ).I find out that instead of using HTML and JS,it can be done using Dash Framework (https://dash.plot.ly/).I read the tutorials but it was of vary different kind and I find difficult to take off.

Any Suggestions on how Can I start?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Add NER output to pandas dataframe dg3000 0 93 Apr-22-2024, 08:14 PM
Last Post: dg3000
  HTML Decoder pandas dataframe column mbrown009 3 1,055 Sep-29-2023, 05:56 PM
Last Post: deanhystad
  Use pandas to obtain cartesian product between a dataframe of int and equations? haihal 0 1,127 Jan-06-2023, 10:53 PM
Last Post: haihal
  Pandas Dataframe Filtering based on rows mvdlm 0 1,446 Apr-02-2022, 06:39 PM
Last Post: mvdlm
  Pandas dataframe: calculate metrics by year mcva 1 2,327 Mar-02-2022, 08:22 AM
Last Post: mcva
  Pandas dataframe comparing anto5 0 1,271 Jan-30-2022, 10:21 AM
Last Post: anto5
  PANDAS: DataFrame | Replace and others questions moduki1 2 1,808 Jan-10-2022, 07:19 PM
Last Post: moduki1
  PANDAS: DataFrame | Saving the wrong value moduki1 0 1,558 Jan-10-2022, 04:42 PM
Last Post: moduki1
  Describe repeating sequences in Dataframe and plot results PBRM 0 1,267 Dec-06-2021, 10:29 PM
Last Post: PBRM
  update values in one dataframe based on another dataframe - Pandas iliasb 2 9,311 Aug-14-2021, 12:38 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020