Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
to_datetime question
#1
I hope you are all having a good day. I have another question. Why does the first code work but the second code doesn't (note, the second code runs, it just doesn't turn my observations into datetime types):

Code 1:

df['timeStamp']=pd.to_datetime(df['timeStamp'])

Code 2:

pd.to_datetime(df[‘timeStamp’])
Reply
#2
pd.to_datetime() returns converted data, it doesnt convert its argument in place. So you need to "capture" it with assigning into a variable (or you can use it as an argument for another function).
Reply
#3
(Mar-29-2017, 09:14 PM)zivoni Wrote: pd.to_datetime() returns converted data, it doesnt convert its argument in place. So you need to "capture" it with assigning into a variable (or you can use it as an argument for another function).

Thanks!!! This helped me understand the concept.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020