在这个例子中,我想为每一排购买最高速度的汽车,因为它有刹车(如果两者都没有刹车,它们同样有吸引力)
import pandas as pd
ExampleOfWhatIHave = {'Car51-speed':[1, 200, 19, 18],
'Car52-speed':[20, 21, 19, 18],
'Car51-brakes':[True, True, False, False],
'Car52-brakes':[True, True, False, True]}
ExampleOfWhatINeed = {'Car51-speed':[1, 200, 19, 180],
'Car52-speed':[20, 21, 19, 18],
'Car51-brakes':[True, True, False, False],
'Car52-brakes':[True, True, False, True],
'Cartobuy': [['Car52'],['Car51'],['Car52','Car51'],['Car52']]}
# Create DataFrame
df = pd.DataFrame(ExampleOfWhatINeed)
请想象现实中汽车和变量的数量非常大(因此为51,52),因此“-”是可以用来循环它们的有意义的区别,而不是索引(我故意简化了它)
另一种选择:
df
:解释:
使用制动值屏蔽超速:
brake_m
然后根据最大值屏蔽超速值(如果有多个最大值,则保持)
cars
:speed_m
然后将行聚集到列表中并分配回数据帧:
完整的工作示例:
尝试:
印刷品:
相关问题 更多 >
编程相关推荐