I have a dataframe df with time index (15 minutes time steps) with values representing a leap year (2012). The Goal is to use the same values of df for the next years considering the fact of next not leap and leap years. It means the values have to be same for all months except for February which varying between 28 and 29 days.
I did the following steps: given is dataframe df for the year 2012
I separately create a data range of the next 10 years starting with 2012 ending at 2022
I used the pandas concat() function with this following code line to replicate the values of df:
df_until_2022= pd.concat([df]*10, ignore_index=True)I used the the pandas join() and set_index() functions in order to set the new data range from step 1 with the next 5 years as index.
The issue now is the number of rows which depends on the type of the year (leap or not leap)
The question: how to automatically check the type of the next year and replicate the value of the given dataframe df based on that check-information?
Use:
Idea is add new row with last Timestamp, here
2022-12-31 23:45:00and then create15MinDatetimeindex byDataFrame.asfreq, last copy first year data byGroupBy.ffill:Another solution is create all datetimes by
DataFrame.reindex, then join values with omit first 4 year values in second level and convert to datetimes byto_datetimewitherrors='coerce'- it replace 29 February datetimes toNaTif not exist, so last remove this rows byIndex.notnainboolean indexing: