[英]yyyy-MM-ddT00:00:00 to yyyy-MM-dd 00:00:00 in Pandas dataframe
I believe that my problem is really straightfoward and there must be a really easy way to solve this issue with pandas that I am still not aware of. 我认为我的问题确实很直截了当,必须有一种非常简单的方法来解决我仍然不知道的熊猫问题。
The problem is that I have one column on a pandas dataframe which all the elements are written on this following format: 问题是我在熊猫数据框上有一列,所有元素都以以下格式编写:
yyyy-MM-ddT00:00:00
I want to translate each element of the column to the following format: 我想将列的每个元素转换为以下格式:
yyyy-MM-dd 00:00:00
And also, afterwards, is it possible from this column of the dataframe, create two more columns now dividing into date and time. 而且,之后,是否有可能从数据框的此列中创建另外两列,现在将其划分为日期和时间。 What I mean is, to get: 我的意思是,要获得:
yyyy-MM-dd 00:00:00
to two more columns, one containing the date: 到另外两列,其中一列包含日期:
yyyy-MM-dd
And the other containing the time: 另一个包含时间:
00:00:00
Hope that I could synthetize everything properly. 希望我能正确地综合一切。 Thank you in advance. 先感谢您。
How about pd.Series.str.split
pd.Series.str.split
怎么pd.Series.str.split
# import pandas as pd
# df = pd.DataFrame({'Date': ['2019-08-29T12:00:00']})
# Date
# 0 2019-08-29T12:00:00
df.Date.str.split('T', expand=True)
# 0 1
# 0 2019-08-29 12:00:00
To simply get rid of the T
between date and time string, you could use pd.Series.str.replace
: 要简单地删除日期和时间字符串之间的T
,可以使用pd.Series.str.replace
:
df.Date.str.replace('T', ' ')
# 0 2019-08-29 12:00:00
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.