Hi,
Anyone face the current issue AttributeError: Can only use .dt accessor with datetimelike values ?
Seem like having issue with pandas, did try to solve this by
weather[‘Date’] = pd.to_datetime(weather[‘Date’], format = ‘%Y-%b-%d’)
But that generate another problem later in the code.
~/.conda/envs/tf-gpu/lib/python3.6/site-packages/pandas/core/indexes/accessors.py in maybe_to_datetimelike(data, copy)
83 raise TypeError("cannot convert an object of type {0} to a "
—> 84 “datetimelike index”.format(type(data)))
85
TypeError: cannot convert an object of type <class ‘pandas.core.series.Series’> to a datetimelike index
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last)
in ()
----> 1 add_datepart(weather, “Date”)
2 add_datepart(googletrend, “Date”)
3 add_datepart(train, “Date”)
4 add_datepart(test, “Date”)
/opt/project/fastai/courses/dl1/fastai/structured.py in add_datepart(df, fldname, drop)
107 for n in (‘Year’, ‘Month’, ‘Week’, ‘Day’, ‘Dayofweek’, ‘Dayofyear’,
108 ‘Is_month_end’, ‘Is_month_start’, ‘Is_quarter_end’, ‘Is_quarter_start’, ‘Is_year_end’, ‘Is_year_start’):
–> 109 df[targ_pre+n] = getattr(fld.dt,n.lower())
110 df[targ_pre+‘Elapsed’] = fld.astype(np.int64) // 10**9
111 if drop: df.drop(fldname, axis=1, inplace=True)
~/.conda/envs/tf-gpu/lib/python3.6/site-packages/pandas/core/generic.py in getattr(self, name)
3075 if (name in self._internal_names_set or name in self._metadata or
3076 name in self._accessors):
-> 3077 return object.getattribute(self, name)
3078 else:
3079 if name in self._info_axis:
~/.conda/envs/tf-gpu/lib/python3.6/site-packages/pandas/core/base.py in get(self, instance, owner)
241 # this ensures that Series.str. is well defined
242 return self.accessor_cls
–> 243 return self.construct_accessor(instance)
244
245 def set(self, instance, value):
~/.conda/envs/tf-gpu/lib/python3.6/site-packages/pandas/core/series.py in _make_dt_accessor(self)
2820 return maybe_to_datetimelike(self)
2821 except Exception:
-> 2822 raise AttributeError("Can only use .dt accessor with datetimelike "
2823 “values”)
2824
AttributeError: Can only use .dt accessor with datetimelike values