I have a dataframe with gaps
temperature
data
2016-01-01 01:00:00 -8.2
2016-01-01 02:00:00 -8.3
2016-01-01 03:00:00 -9.1
2016-01-01 04:00:00 -9.1
2016-01-01 05:00:00 -9.6
... ...
2020-02-29 20:00:00 5.9
2020-02-29 21:00:00 5.4
2020-02-29 22:00:00 4.7
2020-02-29 23:00:00 4.3
2020-03-01 00:00:00 4.3
Here is the code for some sample data, different from mine but the concept is the same:
def tworzeniedaty():
import pandas as pd
rng1 = list(pd.date_range(start='2016-01-01', end='2016-02-29', freq='D'))
rng2 = list(pd.date_range(start='2016-12-15', end='2017-02-28', freq='D'))
rng3 = list(pd.date_range(start='2017-12-15', end='2018-02-28', freq='D'))
rng4 = list(pd.date_range(start='2018-12-15', end='2019-02-28', freq='D'))
rng5 = list(pd.date_range(start='2019-12-15', end='2020-02-29', freq='D'))
return rng1 + rng2 + rng3 + rng4 + rng5
import random
import pandas as pd
lista = [random.randrange(1, 10, 1) for i in range(len(tworzeniedaty()))]
df = pd.DataFrame({'Date': tworzeniedaty(), 'temperature': lista})
df['Date'] = pd.to_datetime(df['Date'], format="%Y/%m/%d")
When I plot the data I get a very messy plot.
Instead I would like to get:
It is the same question as How to plot only specific months in a time series of several years? but I would like to do it in python and can't decipher R code.