Quantcast
Viewing all articles
Browse latest Browse all 14069

Plotly: How to show trendline for time series data using plotly express?

Using the built in "tips" dataframe in plotly express, I first create a datetime column.

import plotly.express as pximport pandas as pdfrom datetime import datetimedf_tips = px.data.tips()datelist = pd.date_range(datetime.today(), periods=df_tips.shape[0]).tolist()df_tips['date'] = datelist

Using a column of datetimes as the x-axis gives the error:

px.scatter(df_tips,x='date',y='tip',trendline='ols')    ...TypeError: cannot astype a datetimelike from [datetime64[ns]] to [int32]

Using any other column does not. Is there a good way to do this?


Viewing all articles
Browse latest Browse all 14069

Trending Articles