0

I am trying to convert my column 'Time' to the correct timedelta data type so I can use comparisons to drop certain times out of the data frame later in the code, but I am coming across a ValueError "ValueError: Could not convert 'Time' to NumPy timedelta"

df['Dates'] = pd.to_datetime(df['Date/Time (earliest)']).dt.date
df['Time'] = pd.to_datetime(df['Date/Time (earliest)']).dt.time


df['Time'] = pd.to_timedelta(['Time'])

The first two lines work, but the last does not...

dataframe output before error

Addi O
  • 11
  • 1
  • 1
    [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) ... Please don't post images of code, data, or Tracebacks. Copy and paste it as text then format it as code (select it and type `ctrl-k`) … [Why should I not upload images of code/data/errors when asking a question?](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors-when-asking-a-question) – wwii Jun 14 '22 at 21:05
  • How will you use that column for comparisons? – wwii Jun 14 '22 at 21:08
  • What's your expected output? For example, what do you want to obtain when you use `pd.to_timedelta(['Time'])` on the first value of the column "Time"? – Ignatius Reilly Jun 14 '22 at 22:12

0 Answers0