I'm facing a problem in converting dates in my dataframe.
Example:
col1 col2
1 2018-10-02 2018-07-03
09:00:00+00 23:56:09.134+00
2 2018-07-03 2018-10-02
23:56:09.134+00 09:00:00+00
df.dtypes
col1 object
col2 object
Due to the fact that I need to do some ML on the dataset, I need to transform the dates into a float, so in the julian format.
I tried a lot of things like: Calculating julian date in python or
df['col1'] = df['col1'].dt.strftime("%y%j")
The example above works well after having converted the column to_datetime, but it raises an error if I pass df[['col1', "col2"]]
:
AttributeError: 'DataFrame' object has no attribute 'dt'
I've also problem with the format, since some obs does have milliseconds and some doesn't. I can drop them I think, but also in this case I don't know how.
Also I'm not able to find a julian format which is extended up to the seconds (%y%j is not enough, and I don't know which letters of the format I need)
I have many other columns with dates in my df, so there is a simple way to convert all of them?
Thanks