Skip to content
Advertisement

How to organise multiple stock data in pandas dataframe for plotting

I have over a hundred stocks (actually crypto but that does not matter) I wish to plot, all on the same line plot.

JavaScript

I end up with a dataframe that looks like this:

JavaScript

I don’t know how to make a line plot from this dataframe, I don’t even know if it is possible. Is there a way? Or is there a better way I should structure the data?

Advertisement

Answer

It maybe better if you transform the data as shown in example belo.

JavaScript
stock price time
A 10 1
A 20 2
A 30 3
A 40 4
B 1 1
B 2 2
B 3 3
B 4 4

Then, use plotly.express to plot the line chart of each stocks by using

JavaScript

Output:

enter image description here

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement