【发布时间】:2019-07-18 04:33:18
【问题描述】:
如here 所述,Pandas.sort_index() 在对 DateTimeIndex 进行排序时有时会发出 FutureWarning。该问题不可操作,因为它不包含 MCVE。这是一个:
import pandas as pd
idx = pd.DatetimeIndex(['2017-07-05 07:00:00', '2018-07-05 07:15:00','2017-07-05 07:30:00'])
df = pd.DataFrame({'C1':['a','b','c']},index=idx)
df = df.tz_localize('UTC')
df.sort_index()
警告看起来像:
FutureWarning:将时区感知的 DatetimeArray 转换为 具有 'datetime64[ns]' dtype 的时区天真 ndarray
堆栈(Pandas 0.24.1)是:
__array__, datetimes.py:358
asanyarray, numeric.py:544
nargsort, sorting.py:257
sort_index, frame.py:4795
该错误是从 datetimes.py 发出的,要求使用 dtype 参数调用它。但是,没有办法通过 nargsort 一直强制执行该操作——看起来服从 datetimes.py 的请求需要同时更改 pandas 和 numpy。
报告here。同时,您能想出一个我错过的解决方法吗?
【问题讨论】:
标签: pandas