✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Plotting bar chart from CSV file

Hello everyone,
I am attempting to plot a multiple bar charts on the same axis from a CSV file.
This is code that I have, however, I want have more than 10 columns, and don’t want to really do it manually.

I am assuming the best option is to create a pandas dataframe, and the provide a range using the column index number.

Any advice would be very much appreciated.

Thanks in advance.

import plotly.graph_objects as go
import pandas as pd
#import cufflinks as cf
from plotly.subplots import make_subplots

data= pd.read_csv("path to.csv")

fig = go.Figure()

fig.add_trace(go.Bar(x=data['Column1'],
                     y=data['Column2'],
                     name="Column2",))

fig.add_trace(go.Bar(x=data['Column1'],
                     y=data['Column3'],
                     name="Column3",))
                     
fig.add_trace(go.Bar(x=data['Column1'],
                     y=data['Column4'],
                     name="Column4",))                                          

fig.update_layout(title='Analysis',
                    xaxis_title="Column1",
                    xaxis_dtick=1,
                    yaxis_title="Total number",
                    yaxis_dtick=1,
                    font=dict(
                        family="Courier New, monospace",
                        size=18,
                        color="#000000"
                )
)
fig.show()

with open('plotly_graph_bar.html', 'w') as f:
    f.write(fig.to_html(include_plotlyjs='cdn'))