在while循环中的每个循环之后更新数据帧

时间:2019-05-01 05:29:19

标签: python python-3.x dataframe while-loop

如何成功运行此循环,以使数据框也随每个循环而变化?

代码:

while len(left)>0:
    df1 = pd.DataFrame({'Pid': packed})
    df1['g'] = df1.groupby('Pid').cumcount()
    data['g'] = data.groupby('Pid').cumcount()
    dat = data[data.merge(df1, indicator=True, how='left')['_merge'].eq('left_only')]
    dat = dat.reset_index(drop=True)
    print(dat)

    item_m1 = dat["Weight"]
    item_v1 = dat["Volume"]
    truck_m = truck["Weight"]
    truck_v = truck["Volume"]
    truck_c = truck["Price"]
    id_s1 = dat["Pid"]

    item_m1, item_v1, truck_m, truck_v, truck_c, id_s1 = tolist_converter(item_m1,item_v1,truck_m,truck_v,truck_c, id_s1)

    items_dict1 = dat[["Length","Width","Height","Pid" ]].set_index('Pid', drop =False).T.to_dict('list')
    print("items_dc", items_dict)
    truck_dict1 = truck[["S.no","Length(ft)","Breadth(ft)","Height(ft)","TruckID"]].set_index('S.no').T.to_dict('list')

    lpstatus,value_obj,trucks_used, trucks_status, output_dict1 = allocator(item_m1,item_v1,truck_m,truck_v,truck_c,id_s1)
    string_d1 = string_preprocessing(output_dict1, items_dict1, truck_dict1)
    lef, loade = packer(string_d1)
    packed1 = packed_items(loade)

    left = lef
    packed = packed1
    loaded.update((k + '_1' if k in loaded else k, v) for k, v in loade.items())

我能够更改 packed left 的值,但是我不知道如何更新数据框,即我想要 data 在第二个循环中成为日期

0 个答案:

没有答案