我正在嘗試創(chuàng)建一個包含 18330 行的數(shù)據(jù)框字典。但字典停在第 15275 行。我無法理解相同的根本原因。'''final_dict = dict()item = df1['Item Code']id = df1['store ID']sp = df1['Selling Price']mrp = df1['MRP']for a in range(0, item.__len__()): key = str(item[a]) + "|" + str(id[a]) value = str(sp[a]) + "|" + str(mrp[a]) final_dict[key] = value key_list = final_dict.keys()print(item.__len__())print(len(final_dict))print(len(key_list))print(len(df1.index))df1['key'] = key_listprint(df1)'''Output: 18330152751527518330error : "ValueError: Length of values does not match length of index"數(shù)據(jù)框示例:誰能幫我理解我的錯誤。
1 回答

猛跑小豬
TA貢獻(xiàn)1858條經(jīng)驗(yàn) 獲得超8個贊
ItemCode 和 StoreID 組合可能會在您的數(shù)據(jù)中重復(fù)出現(xiàn)。而且由于鍵已經(jīng)存在于字典中,因此只有值正在更新。檢查您的文件是否有重復(fù)。
添加回答
舉報
0/150
提交
取消