我有以下 pandas dataframe df
column1 column2 list_numbers sublist_column
x y [10,-6,1,-4]
a b [1,3,7,-2]
p q [6,2,-3,-3.2]
Run Code Online (Sandbox Code Playgroud)
sublist_column 将包含“list_numbers”列中的数字,其总和为 0(0.5 是一个容差)我编写了以下代码。
def return_list(original_lst,target_sum,tolerance):
memo=dict()
sublist=[]
for i, x in enumerate(original_lst):
if memo_func(original_lst, i + 1, target_sum - x, memo,tolerance) > 0:
sublist.append(x)
target_sum -= x
return sublist
def memo_func(original_lst, i, target_sum, memo,tolerance):
if i >= len(original_lst):
if target_sum <=tolerance and target_sum>=-tolerance:
return 1
else:
return 0
if (i, target_sum) not in memo:
c = memo_func(original_lst, i + 1, target_sum, memo,tolerance) …Run Code Online (Sandbox Code Playgroud) I have following dataframe
flight_departure arrival_at_desination boarding total_flight_time total_flight_time/2 time_to_collect_bags
0:00 4:00 23:30 4:00 2:00 4:30
9:00 14:30 8:30 5:30 2:45 15:00
flight_departure- 0:00 signifies 12:00 AM
arrival_at_desination- 4:00 signifies 4 AM
boarding = flight_departure-30 minutes(23:30)
total_flight_time=arrival_at_desination-flight_departure(4 hours)
total_flight_time/2-calculates hald time(2 hours in this case)
time_to_collect_bags=arrival_at_desination+30 minutes(4:30AM)
Run Code Online (Sandbox Code Playgroud)
When I try to do the following
df['arrival_at_desination']-df['flight_departure']
Run Code Online (Sandbox Code Playgroud)
It gives me following error
TypeError: unsupported operand type(s) for -: 'datetime.time' and 'datetime.time'
Run Code Online (Sandbox Code Playgroud)
how should I subtract two datetime.time columns?