请问我写的Pandas,如何进行优化和提速?
def pick_SR_1(buyer_information):
global output
global seller_SR
check_information = [x for x in buyer_information[4:14] if x == x]
for i in range(0, len(check_information), 2):
if check_information[i] != '品牌' and check_information[i] != '等级':
check_information[i + 1] = int(check_information[i + 1])
seller_pick_goods = seller_SR[seller_SR['货物数量(张)'] != 0]
for i in range(0, len(check_information), 2):
if seller_pick_goods[(seller_pick_goods[check_information[i]] == check_information[i + 1])]['货物数量(张)'].sum() >= \
buyer_information[2]:
seller_pick_goods = seller_pick_goods[(seller_pick_goods[check_information[i]] == check_information[i + 1])]
start_pick_seller = seller_pick_goods.sort_values(by=['仓库', '货物数量(张)'], ascending=False)
start_pick_seller['累计货物数量(张)'] = start_pick_seller['货物数量(张)'].cumsum()
start_pick_seller['是否拣选'] = 1
start_pick_seller['是否拣选'].where(start_pick_seller['累计货物数量(张)'] <= buyer_information[2], 0, inplace=True)
final_pick_goods_pd = start_pick_seller[start_pick_seller['是否拣选'] == 1]
if len(final_pick_goods_pd) != 0 and final_pick_goods_pd['累计货物数量(张)'].values[-1] < buyer_information[2]:
final_pick_goods_pd = final_pick_goods_pd.append(start_pick_seller.iloc[len(final_pick_goods_pd), :])
elif len(final_pick_goods_pd) == 0:
final_pick_goods_pd = final_pick_goods_pd.append(start_pick_seller.iloc[0, :])
final_pick_goods_index = final_pick_goods_pd.index
final_pick_goods = final_pick_goods_pd['货物数量(张)'].values
if len(final_pick_goods) == 1:
final_pick_goods[0] = buyer_information[2]
else:
final_pick_goods[-1] = buyer_information[2] - final_pick_goods_pd['累计货物数量(张)'].values[-2]
judge_binary_list = seller.index.isin(final_pick_goods_index)
last_pick_goods_number = seller.loc[final_pick_goods_index[-1], '货物数量(张)']
seller.loc[judge_binary_list, '货物数量(张)'] = seller.loc[judge_binary_list, '货物数量(张)'].apply(cut_test)
seller.loc[final_pick_goods_index[-1], '货物数量(张)'] = last_pick_goods_number - final_pick_goods[-1]
final_pick_goods_satisfy = final_pick_goods_pd.apply(check_satisfy, args=(check_information,), axis=1).tolist()
len_of_final_index = len(final_pick_goods_index)
output_append = pd.DataFrame(
{'买方客户': [buyer_information[0]] * len_of_final_index, '卖方客户': seller.iloc[final_pick_goods_index, 0].tolist(),
'品种': ['SR'] * len_of_final_index, '货物编号': seller.iloc[final_pick_goods_index, 2].tolist(),
'仓库': seller.iloc[final_pick_goods_index, 4].tolist(), '分配货物数量': final_pick_goods,
'对应意向顺序': final_pick_goods_satisfy})
output = pd.concat([output, output_append], ignore_index=True)
seller_SR = seller[seller['品种'] == 'SR']
return final_pick_goods_index, final_pick_goods, final_pick_goods_satisfy