【问题标题】:Converting a polars Date column to only Months将极坐标日期列转换为仅月份
【发布时间】:2022-12-13 06:31:04
【问题描述】:

我正在尝试将 polars 数据框中的现有列从日期转换为月份。文档here 我不清楚如何调用这些方法。

在 pandas 中,转换 Date -> Month 看起来像这样:

pd.DatetimeIndex(df['column']).month.astype(np.int16)

什么是极当量?

【问题讨论】:

    标签: python python-polars


    【解决方案1】:

    在应用.month()之前,您需要先创建一个dt对象

    from datetime import date
    dates = pl.date_range(date(2022, 1, 1), date(2022, 3, 1), "1d", name="drange")
    months = dates.dt.month()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-24
      • 1970-01-01
      • 1970-01-01
      • 2020-05-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多