[英]How to covnert int64 data into ?day, month and year?
I have a date feature in the format 20001130 and another 2000-11-30 without any space.我有一个格式为 20001130 的日期功能和另一个没有任何空格的 2000-11-30。 How can i write the optimized code that works for both to split the date into day month and year efficiently
我如何编写适用于两者的优化代码,以有效地将日期拆分为日月和年
You can use pandas.to_datetime
:您可以使用
pandas.to_datetime
:
import pandas as pd
pd.to_datetime([20001130, 20001129], format='%Y%m%d')
or with a dataframe.或使用数据框。
df = pd.DataFrame({'time': [20001129, 20001130]})
df.time = pd.to_datetime(df.time, format='%Y%m%d')
time![]() |
|
---|---|
0 ![]() |
2000-11-29 ![]() |
1 ![]() |
2000-11-30 ![]() |
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.