熊猫DateTimeIndex ceil模糊参数

时间:2019-10-11 14:22:06

标签: python pandas

我试图弄清楚如何传递“模棱两可”的论点。

摘自文档:

[https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DatetimeIndex.ceil.html][1]

rng = pd.date_range('1/1/2018 11:59:00', periods=3, freq='min')
rng.ceil('H')
DatetimeIndex(['2018-01-01 12:00:00', '2018-01-01 12:00:00',
               '2018-01-01 13:00:00'],
              dtype='datetime64[ns]', freq=None)

但是,如果我尝试传递参数,则会收到以下错误:

rng.ceil('H',ambiguous='NaT')
Traceback (most recent call last):

  File "<ipython-input-209-f0e872bc569a>", line 1, in <module>
    rng.ceil('H',ambiguous='NaT')

TypeError: ceil() got an unexpected keyword argument 'ambiguous'

谢谢

1 个答案:

答案 0 :(得分:0)

这对我有用:

rng.ceil(freq='H', ambiguous='NaT')
Out[5]: 
DatetimeIndex(['2018-01-01 12:00:00', '2018-01-01 12:00:00',
           '2018-01-01 13:00:00'],
          dtype='datetime64[ns]', freq=None)