Reputation: 17
I am new to python and am looking for ways in which I can visualise data. I have come across 'Dash' - but wondered how I would show a graph based on data that is saved in a CSV?
Currently I have this.. But it only shows a blank graph.
Any help would be welcomed - thanks in advance.
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.express as px
import pandas as pd
df = pd.read_csv('d6.csv')
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Graph(id="graph"),
html.Button("Switch Axis", id='btn', n_clicks=0)
])
@app.callback(
Output("graph", "figure"),
[Input("btn", "n_clicks")])
def display_graph(n_clicks):
if n_clicks % 2 == 0:
x, y = 'Time', 'R1Temp'
else:
x, y = 'R1Temp', 'Time'
fig = px.line(df, x=x, y=y)
return fig
app.run_server(debug=False)
Upvotes: 2
Views: 1311
Reputation: 538
Pandas is your friend, it gives you access to a data structure called a dataframe. I highly recommend you look through some tutorials on pandas as they come up everywhere in the data science field. In addition plotly often looks for dataframes as inputs into their API. https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html
But to cut to the chase, a dataframe can load a CSV with 100% structure retention https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html#pandas.read_csv
https://datatofish.com/export-dataframe-to-csv/
Once you load the csv to a dataframe you can access rows and columns with queries. https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.columns.html
Upvotes: 1