I have a pandas series object consists of a datetime_index and some values, looks like following:
df
2020-01-01 00:00:00 39.6
2020-01-01 00:15:00 35.6
2020-01-01 00:30:00 35.6
2020-01-01 00:45:00 39.2
2020-01-01 01:00:00 56.7
...
2020-12-31 23:45:00 56.3
I am adding some values to this df
with .append()
. Since it is not sorted then I sort its index via .sort_index()
. However what I would like to achieve is that I want to sort only for given day.
So for example I add some values to day 2020-01-01
, and since the added values will be after the end of the day 2020-01-01
I just need to sort the first day of the year. NOT ALL THE DF.
Here is an example, NaN value is added with .append()
:
df
2020-01-01 00:00:00 39.6
2020-01-01 00:15:00 35.6
...
2020-01-01 23:45:00 34.3
2020-01-01 15:00:00 NaN
...
2020-12-31 23:45:00 56.3
Now I cannot df.sort_index()
, because it breaks other days. That is why I just want to apply .sort_index()
to the day 2020-01-01
. How do I do that?
WHAT I TRIED SO FAR AND DOES NOT WORK:
df.loc['2020-01-01'] = df.loc['2020-01-01'].sort_index()