0

I have a dataframe with to columns looking like this:

        c1.1                        c1.2
    2019-11-01 00:15:00+01:00   1260.00304232804
    2019-11-01 00:30:00+01:00   402.552212643678
    2019-11-01 00:45:00+01:00   524.666157608132
    2019-11-01 01:00:00+01:00   476.758148148148
    2019-11-01 01:15:00+01:00   492.47544534413

I would like to convert both to floats. I have tried using df['c1.1'].astype(float), however, this does not work due to the first column being datetime.datetime. I get the following error: float() argument must be a string or a number, not 'datetime.datetime'

I've also tried converting both columns to strings, before turning them into floats, but this is also not working. Error: could not convert string to float: '2019-11-01 00:15:00+01:00'

Does anyone know how to solve this problem? Thank you!

123
  • 39
  • 3
  • 1
    And what value a date will takes when converting as float ? Amount of days/seconds/timestamp ? – azro Jan 07 '21 at 11:29
  • how do you represent datetime as a float? you can use [strftime](https://stackoverflow.com/questions/58977212/numpy-unique-gives-wrong-output-for-list-of-sets) for a convertor, but you still need to select what you want the conversion to be, unless you want second from epoch? – Nullman Jan 07 '21 at 11:30
  • Are you looking for this? https://stackoverflow.com/q/15203623/10197418 – FObersteiner Jan 07 '21 at 12:01

0 Answers0