导入日期时间 导入时间 def convert_to_unix(s): 返回time.mktime(datetime.datetime.strptime(s,“%m /%d /%Y%H:%M”)。timetuple()) def return_with_trip_times(month): 持续时间=月份[['tpep_pickup_datetime','tpep_dropoff_datetime']] duration_pickup = [convert_to_unix(x),持续时间为x ['tpep_pickup_datetime']。值] duration_drop = [conversion_to_unix(x),持续时间为x ['tpep_dropoff_datetime']。值] 持续时间=(np.array(duration_drop)-np.array(duration_pickup))/ float(60) new_frame = month [['passenger_count','trip_distance','pickup_longitude','pickup_latitude','dropoff_longitude','dropoff_latitude','total_amount']] new_frame ['trip_times'] =持续时间 new_frame ['pickup_times'] =持续时间 new_frame ['Speed'] = 60 *(new_frame ['trip_distance'] / new_frame ['trip_times']) 返回new_frame
frame_with_durations = return_with_trip_times(month)
时间数据的格式为'1/30/2015 8:29',显示TypeError。