Difficulty in plotting time series data

This is the data I’m working with. It is weekly sales data

I’m trying to plot a line chart with dates on x-axis and weekly sales on y-axis and get this plot:

Here is the code:

merged['Date'] = pd.to_datetime(merged['Date'])
merged = merged.sort_values('Date')
fig = px.line(merged, x='Date', y='Weekly_Sales)

I’m expecting this kind of result:

The last plot is plotted using seaborn and relplot.

Thanks in advance

hi @Moonis
Welcome to the community :wave:

Can you please share access to the data so we can try to run this locally on our computer.

Hi @adamschroeder

Thanks for replying so quickly. I have attached a onedrive link of the csv file

hi @Moonis
The trick is to group by Date so you don’t have overlapping lines. I saved and used your excel sheet as a .csv file and I named it mydata.

import plotly.express as px
import pandas as pd

merged = pd.read_csv('mydata.csv')
merged['Date'] = pd.to_datetime(merged['Date'])
merged = merged.sort_values('Date')
merged = merged.groupby('Date')['Weekly_Sales'].sum().reset_index()

fig = px.line(merged, x='Date', y='Weekly_Sales')
1 Like

That works like a charm. Thank you very much