在具有熊猫时区感知时间戳的地方使用numpy

时间:2019-07-16 16:10:43

标签: python pandas numpy timezone

我正在尝试将numpy.wheredatetime64[ns, UTC]x参数的类型一起使用y

df = pd.DataFrame(
    {'use_date_2': [True, False],
     'date_1': [pd.Timestamp('2018-01-01', tz='UTC'), pd.Timestamp('2018-01-02', tz='UTC')],
     'date_2': [pd.Timestamp('2018-01-06', tz='UTC'), pd.Timestamp('2018-01-07', tz='UTC')],
     })

np.where(df.use_date_2, df['date_2'], df['date_1'])

我收到此警告:

/opt/rh/rh-python36/root/usr/lib64/python3.6/unittest/case.py:643: FutureWarning: Converting timezone-aware DatetimeArray to timezone-naive ndarray with 'datetime64[ns]' dtype. In the future, this will return an ndarray with 'object' dtype where each element is a 'pandas.Timestamp' with the correct 'tz'.
    To accept the future behavior, pass 'dtype=object'.
    To keep the old behavior, pass 'dtype="datetime64[ns]"'.
  testMethod()

出于性能原因,我不想使用对象,所以我应该通过'dtype="datetime64[ns]"'

但是我不知道将dtype参数(哪里只有3个参数)放在哪里

0 个答案:

没有答案