0

I have a dataframe date is a sequence of 15 min intervals time. I want to convert it in matlab datenum.

2018-01-01 01:00:00,"25693,896000000",569321
2018-01-01 01:15:00,"25693,896000000",569321
2018-01-01 01:30:00,"25693,8960000000",569321
2018-01-01 01:45:00,"25693,896000000",569321
2018-01-01 02:00:00,"25693,896000000",569321
2018-01-01 02:15:00,"56932,123000000",369852
2018-01-01 02:30:00,"56932,123000000",369852
2018-01-01 02:45:00,"56932,123000000",369852
2018-01-01 03:00:00,"56932,123000000",369852
2018-01-01 03:15:00,"56932,123000000",369852
2018-01-01 03:30:00,"56932,123000000",369852
the first line of column should be 569321,738157.0104166,2018,1,1,5,0,15,25693,896000000. I found this function

def datenum(d):
    return 366 + d.toordinal() + (d - dt.fromordinal(d.toordinal())).total_seconds()/(24*60*60)

d = dt.strptime('2018-01-01 01:00','%Y-%m-%d %H:%M')
dn = datenum(d)
print(dn)
But here I need to enter each date I have thousands of rows. How can it convert the whole column of date at once? second thing is it only convert date if it is in this format**'2018-01-01 01:00'** if I try to add seconds '2018-01-01 01:00:15' it throws error. can some one please guide how can I do it? any help would be appreciated.
Katja
  • 131
  • 1
  • 6
  • [this](https://stackoverflow.com/a/9391765) or [this](https://stackoverflow.com/a/9260102) answer – mozway May 17 '22 at 08:09
  • how can I call my date column in this function? – Katja May 17 '22 at 08:19
  • @mozway when I am calling the function it is throwing datetime2matlabdn(2021-08-28 10:30:00) ^ SyntaxError: invalid token. if i remove the zeros then it says invalid syntax. – Katja May 17 '22 at 09:15

0 Answers0