Home > Blockchain >  Plotting every day of a timeseries dataframe with subplots
Plotting every day of a timeseries dataframe with subplots

Time:11-18

I have a dataframe whose index is a timeseries. Let's think this is my dataframe:

                       Temp
2019/01/01 00:00:00    25.3
2019/01/01 00:30:00    22.0
2019/01/01 01:00:00    22.1
2019/01/01 01:30:00    28.1
2019/01/01 02:00:00    26.8
2019/01/01 02:30:00    25.3
...
2019/01/02 00:00:00    20.2
2019/01/02 00:30:00    27.0
2019/01/02 01:00:00    27.5
2019/01/02 01:30:00    28.1
2019/01/02 02:00:00    28.8
2019/01/02 02:30:00    26.3
...
2019/02/10 23:30:00    21.6

Can I plot each day in a subplot? For example, can be the figure like 3 columns and all the necessary rows?

I know how to do it manually,

d1 = df.loc['2018/09/01' : '2018/09/01' ]
d1.plot()

But, how can I plot all days? And just a range of N days?

I tried using for loop but the idea is using the power of Pandas.

Thank you very much!!!

CodePudding user response:

First convert the index


B:

CodePudding user response:

Interesting problem. You need to use python GroupBy() object. More info about the object is Plotting based on Day groups

Since you have a time series as the index, you can reindex the dataframe with numbers, assemble only days by using pandas `to_datetime.

pd.to_datetime(DataFrame[["year", "month", "day"]]), add this as a column and then use the .groupby() object

  • Related