Hi i am trying to clean up the column here converting this column to date, but am afraid i was not able to get it.
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from datetime import datetime as dt
%matplotlib inline
This is part of the info for the columns.
S/N 44 non-null int64
Date 44 non-null object
Time of Reporting 44 non-null object
Month 44 non-null int64
When i try this
fraud['Date'] = pd.to_datetime(fraud['Date'], format='%Y%m%d')
i get the following error message
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
C:\ProgramData\Anaconda3_64\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
4380 try:
-> 4381 return libindex.get_value_box(s, key)
4382 except IndexError:
pandas/_libs/index.pyx in pandas._libs.index.get_value_box()
pandas/_libs/index.pyx in pandas._libs.index.get_value_at()
pandas/_libs/util.pxd in pandas._libs.util.get_value_at()
pandas/_libs/util.pxd in pandas._libs.util.validate_indexer()
TypeError: 'str' object cannot be interpreted as an integer
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
<ipython-input-19-b32e0288d98d> in <module>
----> 1 fraud['Date'] = pd.to_datetime(fraud['Date'], format='%Y%m%d')
C:\ProgramData\Anaconda3_64\lib\site-packages\pandas\core\series.py in __getitem__(self, key)
866 key = com.apply_if_callable(key, self)
867 try:
--> 868 result = self.index.get_value(self, key)
869
870 if not is_scalar(result):
C:\ProgramData\Anaconda3_64\lib\site-packages\pandas\core\indexes\category.py in get_value(self, series, key)
452
453 # we might be a positional inexer
--> 454 return super(CategoricalIndex, self).get_value(series, key)
455
456 def _can_reindex(self, indexer):
C:\ProgramData\Anaconda3_64\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
4387 raise InvalidIndexError(key)
4388 else:
-> 4389 raise e1
4390 except Exception: # pragma: no cover
4391 raise e1
C:\ProgramData\Anaconda3_64\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
4373 try:
4374 return self._engine.get_value(s, k,
-> 4375 tz=getattr(series.dtype, 'tz', None))
4376 except KeyError as e1:
4377 if len(self) > 0 and (self.holds_integer() or self.is_boolean()):
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/index_class_helper.pxi in pandas._libs.index.Int8Engine._check_type()
KeyError: 'Date'
i tried googling this problem but not sure what’s causing it. am using PC for this exercise.