Spaces:
Sleeping
Sleeping
File size: 893 Bytes
010071f b8b8eab 010071f b04cfbb b8b8eab b04cfbb b8b8eab 010071f b8b8eab b04cfbb b8b8eab b04cfbb b8b8eab b04cfbb b8b8eab |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import pandas as pd
import plotly.graph_objects as go
def plot_metric_tool(file_path: str, date_col: str, value_col: str):
"""
Generic interactive line chart for any numeric metric.
Returns a Plotly Figure or error message string.
"""
df = pd.read_csv(file_path)
if date_col not in df.columns or value_col not in df.columns:
return f"β '{date_col}' or '{value_col}' column missing."
df[date_col] = pd.to_datetime(df[date_col], errors="coerce")
if df[date_col].isna().all():
return f"β '{date_col}' could not be parsed as dates."
fig = go.Figure(
go.Scatter(
x=df[date_col],
y=df[value_col],
mode="lines+markers",
line=dict(width=2),
)
)
fig.update_layout(title=f"{value_col} Trend", template="plotly_dark")
fig.write_image("metric_plot.png")
return fig
|