0

I am currently trying to plot simple integer values against time using plotly.express, a sample of the data looks like this:

df = 
          TagTimeStamp         COP
0       2019-01-08 01:00:00 2.289827
1       2019-01-08 02:00:00 2.276451
2       2019-01-08 03:00:00 2.249055
3       2019-01-08 04:00:00 2.260732
4       2019-01-08 05:00:00 2.256685
... ... ...
42390   2020-05-29 07:00:00 4.186115
42391   2020-05-29 08:00:00 4.186170
42392   2020-05-29 09:00:00 4.186234
42393   2020-05-29 10:00:00 4.186312
42394   2020-05-29 11:00:00 4.186396

Trying to plot:

import plotly.express as px

fig = px.line(df, x="TagTimeStamp", y="COP")
fig.show()

The figure shown:

enter image description here

I am expecting something like this, shown in the answer of that post.

EDIT: After sorting the dates and averaging values by month, I have a credible output:

import plotly.express as px
import pandas as pd
d = df.sort_values(by='TagTimeStamp', ascending = False)
per_month = d.set_index('TagTimeStamp').groupby(pd.Grouper(freq='M'))['COP'].mean()
x = per_month.index
y = per_month.values
fig = px.line(d, x=x, y=y)
fig.update_xaxes(title="Month and Year")
fig.update_yaxes(title="COP")
fig.show()

enter image description here

Apologies.

S23
  • 119
  • 12
  • `df['TagTimeStamp']=pd.to_datetime(df['TagTimeStamp'])` Is it in time series data format? If not, please add the following code. – r-beginners Dec 02 '21 at 08:28
  • Hello @r-beginners thank you for replying, and yes, it is in time-series format – S23 Dec 02 '21 at 08:29
  • @S23 Those aren't integers. Not that it matters trhough. What matters is your data sample. Running that first snippet would only return raise all kinds of errors. So please take the time to share a reproducible sample of your `df` like [this](https://stackoverflow.com/questions/63163251/pandas-how-to-easily-share-a-sample-dataframe-using-df-to-dict/63163254#63163254) – vestland Dec 02 '21 at 08:40
  • If the data is hourly from the start date to the end date, why is there 42394 data when there are 12169? – r-beginners Dec 02 '21 at 08:46
  • @r-beginners The data is from Jan 2019 - Dec 2020 with a few rows removed due to null values. – S23 Dec 02 '21 at 08:53

0 Answers0