I am trying to sort pandas dataframe by column time of type datetime64.
Here is what I am trying to do.
I do not understand why it is removing the time information. Aby idea how to avoid this?
I am trying to sort pandas dataframe by column time of type datetime64.
Here is what I am trying to do.
I do not understand why it is removing the time information. Aby idea how to avoid this?
This is a consequence of the rendering method __repr__ in the DataFrame class. It is possible some of your rows have a time component of "00:00:00", so it is ignored in the output. It has nothing to do with sort_values.
For example:
df = pd.DataFrame({
'time': pd.date_range('1-1-2020 00:00:00', '1-1-2020 02:00:00', freq='H')})
df
time
0 2020-01-01 00:00:00
1 2020-01-01 01:00:00
2 2020-01-01 02:00:00
df
time
0 2020-01-01 00:00:00 # time component not ignored
1 2020-01-01 01:00:00
2 2020-01-01 02:00:00
df.head(1)
time
0 2020-01-01 # time component ignored because
# there are no other rows have a time component
Your output is correct. You'll also see the final output has rows not shown in the original sample.