0

I am reading this data from my framework and getting it as below:

mped_date = pd.to_datetime(metadata['MPED'].values[0])

>> mped_date: 2017-12-31 00:00:00
type(mped_date)
>> mped_date: <class 'pandas._libs.tslib.Timestamp'>

I have other variables which are of type date and I am unable to compare this with them.I get the below error

TypeError: Cannot compare type 'Timestamp' with type 'date'

Can someone guide me to convert the mped_date to date type ?

PM 2Ring
  • 54,345
  • 6
  • 82
  • 182
  • Also see https://stackoverflow.com/questions/13703720/converting-between-datetime-timestamp-and-datetime64 – PM 2Ring Oct 13 '18 at 02:56
  • 1
    The to_pydatetime method seems to be a much more straightforward approach than the answers suggested in the reported duplicate. Perhaps it wasn't available when that question was posted five years ago. – codingatty Oct 13 '18 at 07:29
  • @codingatty: Yes, please post your solution on the target question and we can upvote it there. We need to prevent duplicates proliferating. – smci Oct 13 '18 at 21:53
  • OK, posted there. – codingatty Oct 13 '18 at 23:52

1 Answers1

1

I don't use pandas, but the pandas doc shows a pandas.Timestamp.to_pydatetime method that sounds like it will do the conversion you need: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Timestamp.to_pydatetime.html

codingatty
  • 2,026
  • 1
  • 23
  • 32