在我的数据框“ df”中,我有一列“ Datetime”,其中包含500行。每行包含一个类似于以下内容的字符串对象: 2018-12-23T10:42:09.690Z
将日期和时间分成两个不同的列(日期和时间)将非常有帮助。
日期 2018-12-23
时间 10:42:09.69
我尝试了以下代码:
componentDidmount
如果我仅在诸如“ 2018-12-23T10:42:09.690Z”之类的特定字符串上使用,它确实可以工作。
#Input:
string = df['Datetime']
#Date
regex_res = re.search(r'(([0-9]{4})[-]([0-9]{2})[-]([0-9]{2}))',string)
print(regex_res.group())
#Output:
TypeError: expected string or bytes-like object
我已经完成的测试:
检查是否为空。输出给我每一行“ False”。
#Input:
test = "2018-12-23T10:42:09.690Z"
#Date
regex_res = re.search(r'(([0-9]{4})[-]([0-9]{2})[-]([0-9]{2}))',test)
print(regex_res.group())
#Output:
2018-12-23
每行的类型均为“类'str'”
nan_rows = [df['Datetime'].isnull()]
我在做什么错? 感谢您的帮助!
此致
Elle