I have some CSV which I want to see as a dashboard, so I can easily explore the data. - Create a dropzone where a user can drop his csv. Once drop, render a table + Interactive charts showing transaction trends, project type distributions, and geographic breakdowns transaction_id,date,project_type,project_id,seller,buyer,quantity,price_per_ton,total_value,standard,vintage_year,location TR-12493,2024-01-15,Reforestation,PRJ-4587,Carbon Forest Partners,GreenInvest Group,5000,12.50,62500.00,Gold Standard,2023,Brazil TR-12494,2024-01-17,Renewable Energy,PRJ-2839,SunPower Solutions,Eco Capital Fund,3200,9.75,31200.00,VCS,2023,India TR-12495,2024-01-21,Methane Capture,PRJ-6721,AgriTech Emissions,Climate Forward,2800,14.25,39900.00,CAR,2023,United States
To upload files, please first save the app
import streamlit as st
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
from datetime import datetime
import io
st.set_page_config(layout="wide")
st.title("Carbon Credits Dashboard")
# File upload
uploaded_file = st.file_uploader("Drop your CSV file here", type=['csv'])
if uploaded_file is not None:
# Read CSV
df = pd.read_csv(uploaded_file)
# Convert date to datetime
df['date'] = pd.to_datetime(df['date'])
# Display raw data in an expandable section
with st.expander("Raw Data"):
st.dataframe(df)
# Create three columns for the metrics
col1, col2, col3 = st.columns(3)
with col1:
st.metric("Total Transactions", len(df))
with col2:
st.metric("Total Volume (tons)", df['quantity'].sum())
with col3:
st.metric("Total Value ($)", f"{df['total_value'].sum():,.2f}")
# Create two columns for charts
col1, col2 = st.columns(2)
with col1:
# Transaction trends over time
fig_trends = px.line(
df.groupby('date').agg({
'total_value': 'sum',
'quantity': 'sum'
}).reset_index(),
x='date',
y=['total_value', 'quantity'],
title='Transaction Trends Over Time'
)
st.plotly_chart(fig_trends, use_container_width=True)
# Geographic distribution
fig_geo = px.pie(
df.groupby('location').agg({
'total_value': 'sum'
}).reset_index(),
values='total_value',
names='location',
title='Geographic Distribution of Transactions'
)
st.plotly_chart(fig_geo, use_container_width=True)
with col2:
# Project type distribution
fig_project = px.bar(
df.groupby('project_type').agg({
'quantity': 'sum',
'total_value': 'sum'
}).reset_index(),
x='project_type',
y=['quantity', 'total_value'],
title='Project Type Distribution',
barmode='group'
)
st.plotly_chart(fig_project, use_container_width=True)
# Price trends by project type
fig_price = px.box(
df,
x='project_type',
y='price_per_ton',
title='Price Distribution by Project Type'
)
st.plotly_chart(fig_price, use_container_width=True)
# Additional analysis section
st.header("Detailed Analysis")
# Standard distribution
col1, col2 = st.columns(2)
with col1:
standard_dist = df.groupby('standard')['quantity'].sum().reset_index()
fig_standard = px.pie(
standard_dist,
values='quantity',
names='standard',
title='Distribution by Standard'
)
st.plotly_chart(fig_standard, use_container_width=True)
with col2:
# Top sellers and buyers
top_sellers = df.groupby('seller')['total_value'].sum().sort_values(ascending=False).head(5)
fig_sellers = px.bar(
top_sellers,
title='Top 5 Sellers by Total Value'
)
st.plotly_chart(fig_sellers, use_container_width=True)
else:
st.info("Please upload a CSV file to begin the analysis.")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?