1

I have a dataframe that looks like this, but with 52 columns:

Day GOOG APPL GE ...
1 100 90 20
2 101 95 21
3 105 100 19

I'd like to plot a multiline like this:

enter image description here

How can I do it for all columns without written column by column:

I'm doing like this:

fig = px.line(cart_acum_t, x=cart_acum_t.index, y=[cart_acum_t[cart_acum_t.columns[0]],cart_acum_t[cart_acum_t.columns[1]],cart_acum_t[cart_acum_t.columns[2]]])
fig.show()

I've tried this:

fig = px.line(cart_acum_t, x=cart_acum_t.index, y=cart_acum_t.columns)
fig.show()

But I received this error:

ValueError: All arguments should have the same length. The length of argument `y` is 53, whereas the length of  previously-processed arguments ['index'] is 2

Thanks in advance!

1 Answers1

0

If you want to plot the index against multiple y-values, you'll probably want to reset the index so it becomes a column, then pass the name of the index to the x argument in px.line:

x_col = cart_acum_t.index.name
cart_acum_t = cart_acum_t.reset_index()

fig = px.line(cart_acum_t, x=x_col, y=cart_acum_t.columns)
fig.show()
Derek O
  • 16,770
  • 4
  • 24
  • 43
  • I tried and I got this error: ValueError: All arguments should have the same length. The length of argument `y` is 58, whereas the length of previously-processed arguments ['_index'] is 3 – Luís Henrique Angélico Dec 29 '22 at 14:53