Reason AttributeError: Can only use .dt accessor with datetimelike values

18 Views Asked by At

Hi I am using pandas which has already done the dataset and succeeded, but just added the following; mean_2017 = df[df['Order Date'].dt.year == 2017]['Sales'].mean()

AttributeError                            Traceback (most recent call last)
<ipython-input-119-e88b5143a27a> in <cell line: 2>()
      1 # hitung rata-rata penjualan sales 2017
----> 2 mean_2017 = df[df['Order Date'].dt.year == 2017]['Sales'].mean()

/usr/local/lib/python3.10/dist-packages/pandas/core/indexes/accessors.py in __new__(cls, data)
    510             return PeriodProperties(data, orig)
    511 
--> 512         raise AttributeError("Can only use .dt accessor with datetimelike values")

AttributeError: Can only use .dt accessor with datetimelike values
0

There are 0 best solutions below