How do I get my csv data correctly and use it as dataframe for an example of plotly?

Hi, I have a programm in Python which I want to plot. However when I export the csv file and then try to plot from there I have an empty plot. My program is like that:

stations = [1,2]
C = 200


tasks    = ['w01','w02','w03']

durations = {(1,'BTC1','w01'):150, (1,'BTC1','w02'):115, (1,'BTC1','w03'):135,
             (1,'BOC1','w01'):150, (1,'BOC1','w02'):115, (1,'BOC1','w03'):135,
             (2,'BTC1','w01'):150, (2,'BTC1','w02'):115, (2,'BTC1','w03'):135,
             (2,'BOC1','w01'):150, (2,'BOC1','w02'):115, (2,'BOC1','w03'):135}

successors = {'w01':[],'w02':['w01'],'w03':['w02']}

types = ['BTC1','BOC1']

f_cost = {(1,'BTC1'): 50000,(1,'BOC1'): 40000,
          (2,'BTC1'): 50000,(2,'BOC1'): 40000}

edges, v_cost = gp.multidict({
    (1,'BTC1','w01'): [15],
    (1,'BTC1','w02'): [30],
    (1,'BTC1','w03'): [45],
    (2,'BTC1','w01'): [15],
    (2,'BTC1','w02'): [30],
    (2,'BTC1','w03'): [45],
    (1,'BOC1','w01'): [50],
    (1,'BOC1','w02'): [80],
    (1,'BOC1','w03'): [110],
    (2,'BOC1','w01'): [50],
    (2,'BOC1','w02'): [80],
    (2,'BOC1','w03'): [110]
})

x_arcs = [(i,j,k) for i in stations for j in types for k in tasks]
y_arcs = [(i,j) for i in stations for j in types]

m = gp.Model()
y = m.addVars(y_arcs, vtype = GRB.BINARY, name = 'y')
x = m.addVars(x_arcs, vtype = GRB.CONTINUOUS, name = 'x',ub=1)

for i in stations:
    for j in types:
        for k in tasks:
            m.addConstr((y[i,j] == 0) >> (x[i,j,k] == 0))
    
m.addConstrs(quicksum(x[i,j,k] for i in stations for j in types) == 1 for k in tasks)

m.addConstrs(quicksum(durations[i,j,k]*x[i,j,k] for j in types for k in tasks) <= C for i in stations)

m.addConstrs(quicksum(y[i,j] for j in types) == 1 for i in stations)

m.addConstrs(quicksum(x[i,j,k] for i in stations for j in types) <= 
             quicksum(x[i,j,l] for i in stations for j in types) 
             for l in tasks for k in successors[l] if l!= 'w01')

m.setObjective(x.prod(v_cost) + y.prod(f_cost), GRB.MINIMIZE)
m.optimize()

What I want is a simple horizontal bar chart where I can get information about which station is assigned to which tasks etc. Basically something like that would be enough:

Therefore I thought of using the example from plotly:

import plotly.express as px
df = px.data.tips()
fig = px.bar(df, x="total_bill", y="sex", color='day', orientation='h',
             hover_data=["tip", "size"],
             height=400,
             title='Restaurant bills')
fig.show()

How can I use this example with my own values? I really appreciate any help so much. Thanks

Hi @plotit1

your input seems to be a CSV file. The example you cited uses pandas:

https://pandas.pydata.org/

Once your read the CSV file with pandas, for example like this: df = pandas.read_csv(filepath), you can manipulate it and use it directly within plotly.express.

I think there is something wrong with my csv file the values in there make no sense. Could you provide me a solution for my exackt programm how you would do the chart like I want it? Thanks

When I do this:

df = pd.read_csv("C:\\Users\\Wiwi-Admin\\bsp.csv")
trace     = go.Bar(x=["task"], y=["station"])
layout    = go.Layout(title='Ablaufplanung', plot_bgcolor="rgb(230,230,230)",
                   showlegend = True)
figure    = go.Figure(data=[trace], layout = layout)
figure.show()

I get no error yes but all I get is a blank diagramm like this:

But it should be like the one image I uploaded in the first comment

px.bar is not the same as go.Bar

https://plotly.com/python-api-reference/generated/plotly.graph_objects.Bar.html

https://plotly.com/python-api-reference/generated/plotly.express.bar.html

The figure is correct as it is, since you never specify that β€œtask” or β€œstation” is a column of your DataFrame.

how can I specify that these are columns of my dataframe. How do I have to make the csv Output so that these are really columns?

Come on, if you had taken a look into the pandas link I provided above, you would know how to do this.

why always people who know how to program are assuming that everyone has to know how it goes? I cant do it I am stupid as hell and not as smart as you guys unfortunatelly. If I would knew how I would ask for help I assume. But still thanks for your efforts. Just dont think that everything is easy for everyone when it is easy for you…

I really think you have no reason for being rude. I am not assuming anything. I am not smart. It is never easy for me.

I always try is to solve my problems on my own. I google my a*! off and if I don’t find anything, I ask for help. But I don’t expect the people to provide solutions for my exact problems.

If the problems I google cannot help me it is not possible for me to solve the problem because of my little knowledge. But maybe someone more professional could solve the problem very easily. That is what I think, I also google and try for days before asking a question in forum. I think no one will help anymore because of the spam here, thanks for that. :grinning:

hi @plotit1
Are you able to share your csv sheet or a sample data that we can work with to try to create the chart you want? (I usually share sample data via google share drive)

hi @adamschroeder the sample data should be the data from my code I posted above. What I want to plot is the x values which are != 0 in my optimization programm in the x axis and the y values which are !=0 (so 1 because y is binary) in the y axis or in boxes like the picture. So that in the end I can have a schedule like visualization where you can see my tasks x values and stations y values.(like the image I posted in the first comment). When I make the csv file to save my solution I get very confusing csv file where only x values are printed. My problem is therefore to correctly outsource my solutions of programming to a csv file which contains at least x and y variables computed within the program correctly. Here is the csv file.https://www.dropbox.com/s/9xhb70j58ck6d53/out.csv?dl=0