我有表格的资料
>>> df['image-capture_time'].iloc[-20:]43 2022-07-19 20:08:26.603000+00:00
36 2022-07-19 20:08:28.313000+00:00
35 2022-07-19 20:08:29.571000+00:00
40 2022-07-19 20:08:30.796000+00:00
38 2022-07-19 20:08:32.062000+00:00
39 2022-07-19 20:08:33.346000+00:00
42 2022-07-19 20:08:34.579000+00:00
41 2022-07-19 20:08:35.813000+00:00
34 2022-07-19 20:08:37.062000+00:00
37 2022-07-19 20:08:38.314000+00:00
130 2022-07-22 15:12:05.925000+00:00
127 2022-07-22 15:12:07.531000+00:00
122 2022-07-22 15:12:08.765000+00:00
123 2022-07-22 15:12:10.031000+00:00
124 2022-07-22 15:12:11.298000+00:00
129 2022-07-22 15:12:12.548000+00:00
128 2022-07-22 15:12:13.781000+00:00
125 2022-07-22 15:12:15.032000+00:00
121 2022-07-22 15:12:16.298000+00:00
126 2022-07-22 15:12:17.532000+00:00
Name: image-capture_time, dtype: datetime64[ns, UTC]通过增加pandas.Timestamp正确排序的值。但使用
iloc[df['image-capture_time'].idxmax()]不返回具有最大时间的记录:
>>> df['image-capture_time'].iloc[df['image-capture_time'].idxmax()]Timestamp('2022-07-22 15:12:11.298000+0000', tz='UTC')>>> df['image-capture_time'].iloc[-1]Timestamp('2022-07-22 15:12:17.532000+0000', tz='UTC')>>> df['image-capture_time'].idxmax()126>>> df['image-capture_time'].iloc[131]Timestamp('2022-07-22 15:12:17.532000+0000', tz='UTC')这里发生了什么事?显然,我对[iloc][1]、idxmax或两者(甚至可能是[pandas.Timestamp][3])都不太了解。
发布于 2022-07-22 16:25:20
使用.loc,而不是.iloc。后者将按位置分割;前者按索引(这是您想要的)进行分割。
https://stackoverflow.com/questions/73083316
复制相似问题