这是我的尝试,我认为它应该有效,虽然我不确定你想用什么过程来检查它是否是当前日期。
第一部分将稍微整理一下,把每一行的字符串转换成日期时间对象。
这个检查的第二部分将弹出一个列,根据每行的系统时钟给出True/False。这是用python 3.5.2完成的。import string
import pandas as pd
import datetime
#Converts each string into a datetime object
def convert_date(row):
trim_date = row[4:-4]
remove_punc = trim_date.translate(trim_date.maketrans('','',string.punctuation))
return datetime.datetime.strptime('2017 ' + remove_punc, '%Y %d %b %H%M')
df['datetime_convert'] = df['from'].apply(convert_date)
#Creates column to check if every value matches the current time on your system
def check_is_now(row):
if str(row) == datetime.datetime.today().strftime('%Y-%m-%d %H:%M:00')::
return True
else:
return False
df['is_now'] = df['datetime_convert'].apply(check_is_now)