Moonis
April 26, 2022, 4:20pm
1
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)
fig.show()
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
Can you please share access to the data so we can try to run this locally on our computer.
Moonis
April 26, 2022, 4:43pm
3
CSV File
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()
print(merged.head(20))
fig = px.line(merged, x='Date', y='Weekly_Sales')
fig.show()```
1 Like
Moonis
April 26, 2022, 8:56pm
5
That works like a charm. Thank you very much