0

I got a dataframe that has some columns, i need to use that data to plot a plotly line chart graph.

ORIGEN TIMESTAMP DATE
ORANGE 2023-02-03 00:00:00
ORANGE 2023-02-03 00:00:00
ORANGE 2023-02-10 00:00:00
APPLE 2023-02-24 00:00:00
APPLE 2023-04-18 00:00:00
APPLE 2023-04-18 00:00:00

I need to transform it to this form.

ORIGEN TIMESTAMP DATE COUNT
ORANGE 2023-02-03 00:00:00 2
ORANGE 2023-02-10 00:00:00 1
APPLE 2023-02-24 00:00:00 1
APPLE 2023-04-18 00:00:00 2

I tried using PD.MELT and groupby but it didn't work. I'm trying to replicate something like this:

Plotly Graph that I need to replicate with my data.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158

1 Answers1

0
# load the markdown table from the OP    
df = pd.read_html('https://stackoverflow.com/q/76948973/7758804')[0]

df["TIMESTAMP DATE"] = pd.to_datetime(df["TIMESTAMP DATE"])

# Transform the DataFrame
transformed_df = df.groupby(["ORIGEN", "TIMESTAMP DATE"]).size().reset_index(name="COUNT")

# Create a line chart using Plotly Express
fig = px.line(transformed_df, x="TIMESTAMP DATE", y="COUNT", color="ORIGEN")

# Show the plot
fig.show()
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Mohamed Darwesh
  • 659
  • 4
  • 17