I have this problem with converting string to datetime in python. but it didn't work.
Asked
Active
Viewed 36 times
-1
-
Please post you code and error output as text. Screenshots of code can not be accepted on Stack Overflow. – Klaus D. Jun 04 '21 at 08:33
2 Answers
0
For 193003, The format should be
# change data type to str if not already the case
cus_data["TYMD"] = cus_data["TYMD"].astype(str)
cus_data["TYMD"] = cus_data["TYMD"].str[:4] + "-" + cus_data["TYMD"].str[4:]
or
cus_data["TYMD"] = cus_data["TYMD"].apply(lambda x: str(x)[:4] + "-" + str(x)[4:])

AmineBTG
- 597
- 3
- 13
-
OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 9999-12-01 00:00:00 what's wrong?:( – 박혜림 Jun 04 '21 at 08:38
-
-
I just want to convert a string series to a date type. And it wants to be expressed like '1930-03'. – 박혜림 Jun 04 '21 at 08:50
-
you shold use other string method as the date is not a complete date. check my answer – AmineBTG Jun 04 '21 at 08:53
0
%y
is for short year. Ex, 2018 will be represented as 18, and %Y
is for long year. In your case, your format is %y-%m
, so your format should be 30-03
. If you want the full year, %Y%m
will work.
-
OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 9999-12-01 00:00:00 what's wrong?:( – 박혜림 Jun 04 '21 at 08:44
-
https://stackoverflow.com/questions/32888124/pandas-out-of-bounds-nanosecond-timestamp-after-offset-rollforward-plus-adding-a refer to this – Jun 04 '21 at 08:50