Series astype() doesn't convert int64 to datetime64 using M8[D] anymore
See original GitHub issueadd units='D'
to Timestamp/to_datetime
epoch support
I have an int64 series representing days since epoch which I’d like to convert to datetime64. This works in 11.0 but raises an exception in 0.11.1.dev-964516a. The exception message is “TypeError: cannot convert datetimelike to dtype [datetime64[D]]”.
import pandas as pd
s = pd.Series([0,1,2])
print s.astype('M8[D]')
My workaround is:
import pandas as pd
s = pd.Series([0,1,2])
print pd.Series(s.values.astype('M8[D]'))
Issue Analytics
- State:
- Created 10 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Issue with converting a pandas column from int64 to datetime64
dtypes is int64 . That's after I used pd. to_datetime(dataset. Year, format='%Y') to convert the column from int64 to datetime64.
Read more >pandas.Series.astype — pandas 1.5.2 documentation
Cast a pandas object to a specified dtype dtype . Parameters. dtypedata type, or dict of column name -> data type. Use a...
Read more >Pandas Change String to Date in DataFrame
Pandas change or convert DataFrame Column Type From String to Date type datetime64 Format - You can change the pandas DataFrame column type ......
Read more >Source code for matplotlib.dates
See :mod:`matplotlib.ticker` for general information on tick locators and ... convert from datetime64 to datetime: dt = dt.tolist() # datetime64 is always ...
Read more >Convert the column type from string to datetime format in ...
We cannot perform any time series based operation on the dates if they are ... Now we will convert it to datetime format...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
this is on purpose, try this for converting from epoch (the docs for this are not fully merged yet):
I have never seen anyone specify epoch as you have an mean Days…what is the use case (most epcoh is seconds, but usually ms)
I guess could add
unit=D
as wellclosed via #3973