Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python script to process CSV files and generate formatted output #15

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added New Text Document.txt
Empty file.
47 changes: 45 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,45 @@
# Quantium starter repo
This repo contains everything you need to get started on the program! Good luck!
import pandas as pd
import dash
from dash import dcc, html
from dash.dependencies import Input, Output
import plotly.express as px

# Read the CSV file containing sales data
sales_data = pd.read_csv('https://gist.githubusercontent.com/chriddyp/c78bf172206ce24f77d6363a2d754b59/raw/c353e8ef842413cae56ae3920b8fd78468aa4cb2/usa-agricultural-exports-2011.csv')


# Convert 'date' column to datetime
sales_data['date'] = pd.to_datetime(sales_data['date'])

# Sort data by date
sales_data = sales_data.sort_values(by='date')

# Initialize the Dash app
app = dash.Dash(__name__)

# Define the layout of the app
app.layout = html.Div([
html.H1("Pink Morsel Sales Visualizer"),
dcc.Graph(id='sales-chart'),
])

# Define callback to update the chart based on user input
@app.callback(
Output('sales-chart', 'figure'),
[Input('sales-chart', 'hoverData')]
)
def update_chart(hoverData):
# Filter data before and after the price increase
before_increase = sales_data[sales_data['date'] < '2021-01-15']
after_increase = sales_data[sales_data['date'] >= '2021-01-15']

# Create line chart
fig = px.line(sales_data, x='date', y='Sales', title="Sales Before and After Pink Morsel Price Increase")

# Highlight the price increase date
fig.add_vline(x='2021-01-15', line_dash="dash", annotation_text="Price Increase", annotation_position="top right")

return fig

if __name__ == '__main__':
app.run_server(debug=True)
35 changes: 35 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.


from dash import Dash, html, dcc
import plotly.express as px
import pandas as pd

app = Dash(__name__)

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
"Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
"Amount": [4, 1, 2, 2, 4, 5],
"City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

app.layout = html.Div(children=[
html.H1(children='Hello Dash'),

html.Div(children='''
Dash: A web application framework for your data.
'''),

dcc.Graph(
id='example-graph',
figure=fig
)
])

if __name__ == '__main__':
app.run(debug=True)
27 changes: 27 additions & 0 deletions script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pandas as pd

# Read CSV files
df1 = pd.read_csv('data/file1.csv')
df2 = pd.read_csv('data/file2.csv')
df3 = pd.read_csv('data/file3.csv')

# Filter rows by product
df1 = df1[df1['product'] == 'Pink Morsels']
df2 = df2[df2['product'] == 'Pink Morsels']
df3 = df3[df3['product'] == 'Pink Morsels']

# Create 'Sales' column
df1['Sales'] = df1['quantity'] * df1['price']
df2['Sales'] = df2['quantity'] * df2['price']
df3['Sales'] = df3['quantity'] * df3['price']

# Keep only required columns
df1 = df1[['Sales', 'date', 'region']]
df2 = df2[['Sales', 'date', 'region']]
df3 = df3[['Sales', 'date', 'region']]

# Concatenate DataFrames
result = pd.concat([df1, df2, df3])

# Write to output CSV file
result.to_csv('output.csv', index=False)