Question: I have the following code: def campaign_plot(col1,col2): grouper = df.groupby(['Day','Campaign']).agg({col1: 'sum', col2: 'mean'}).unstack() result = grouper.fillna(0) fig = go.Figure() fig.add_trace(go.Scatter( x = result.index, y = result.iloc[:, [0, 4]], #<--- name = '1', line = dict( color = ('rgb(205, 12, 24)'), width = 2) )) fig.show()  I want to create a plot using the first and fifth columns of a dataframe. If i just do result.iloc[:, [0, 4]] this outputs the correct columns of the dataframe. But in the plot it just outputs two points. How can I fix this? EDIT: Here is a snippet of the dataframe, which is grouped:  Day Campaign Clicks CTR 0 2013-08-05 1 0 0 1 2013-08-05 3 1 0.5 2 2013-08-05 7 0 0.2 3 2013-08-05 15 5 3 4 2013-08-08 1 6 0.1 5 2013-08-08 3 1 0 6 2013-08-08 7 15 4.5 7 2013-08-08 15 0 1 8 2013-08-10 1 6 2.2 9 2013-08-10 3 20 0 10 2013-08-10 7 1 0.2 11 2013-08-10 15 1 0.1  So in the function, col1 is Clicks and col2 is CTR. Clicks is summed while CTR is averaged. The above dataframe is then grouped by Campaign and by Day, so that in the graph the x axis is the day and each Campaign has a separate line.

Answer: Another approach would be to melt you dataframe. Here is an example of how you could do this.Suppose that you have the following dataframe:  Date High Low Open Close Volume \ 0 2019-01-02 19.000000 17.980000 18.010000 18.830000 87148700 1 2019-01-03 18.680000 16.940001 18.420000 17.049999 117277600 2 2019-01-04 19.070000 17.430000 17.549999 19.000000 111878600 3 2019-01-07 20.680000 19.000000 19.440001 20.570000 107157000 4 2019-01-08 21.200001 19.680000 21.190001 20.750000 121271000 .. ... ... ... ... ... ... 458 2020-10-26 84.970001 80.860001 82.550003 82.230003 69423700 459 2020-10-27 82.370003 77.570000 82.000000 78.879997 156669500 460 2020-10-28 78.959999 75.760002 78.730003 76.400002 76529900 461 2020-10-29 79.180000 76.290001 76.750000 78.019997 52784100 462 2020-10-30 77.699997 74.230003 77.089996 75.290001 51349000  and that you wish to plot column High and Close. Then, an easy way to do this would be: pd.options.plotting.backend = "plotly" df.plot(x='Date', y=[ 'High', 'Close']) df_melt = df.melt(id_vars='Date', value_vars=['High', 'Close']) px.line(df_melt, x='Date' , y='value' , color='variable')   EDIT: Adaptation of solution to the actual data  The problem you are facing is the facts that that you have, after grouping, a multi-level indexing, which makes it hard to work with in this context. A work-around is to drop them. I am not an expert but I do this this way (usually). First, I want to drop the indexes in such a way that I will keep track of the columns (the name need to correspond to Clicks and CTR AND Campaign). I therefore need to make the Campaign number a string, then do the groupby that you did df['Campaign'] = df['Campaign'].astype(str) grouper = df.groupby(['Day','Campaign']).agg({'Clicks': 'sum', 'CTR': 'mean'}).unstack()  Now, comes the tricky part of reindexing (uggly but it works) a = grouper.columns ind = pd.Index([e[0] + e[1] for e in a.tolist()]) grouper.columns = ind result = grouper.reset_index()  which gives:  Day Clicks1 Clicks15 Clicks3 Clicks7 CTR1 CTR15 CTR3 CTR7 0 2013-08-05 0 5 1 0 0.0 3.0 0.5 0.2 1 2013-08-08 6 0 1 15 0.1 1.0 0.0 4.5 2 2013-08-10 6 1 20 1 2.2 0.1 0.0 0.2  The last step is the plotting. pd.options.plotting.backend = "plotly" result.plot(x='Day', y=[ 'Clicks1', 'CTR1']) result_melt = result.melt(id_vars='Day', value_vars= ['Clicks1', 'CTR1']) px.line(result_melt, x='Day' , y='value' , color='variable')  In your function, you'll have to replace ['Clicks1', 'CTR1'] by ['col1', 'col2'] which returns the following plot: