熊貓新手,請和我一起裸照。 我正在嘗試合併以下2個數據幀。熊貓:合併2個數據幀
df.head():
x y z w
0 0.0056 11 824 51
1 0.0056 138 546 16
2 0.0056 328 1264 40
3 0.0056 1212 553 91
4 0.0056 1839 388 48
df1.head():
x y z
0 5539.0567 12243 27
1 5873.2923 14474 1540
2 3975.9776 11353 699
3 1508.5975 8250 628
4 66.7913 11812 538
使用下面的命令:
df1 = df1.merge(df, how='left',left_on=(['x','y','z']),right_index=True)
和以下錯誤作物起來:
ValueError: len(left_on) must equal the number of levels in the index of "right"
共有df有11458060行,而df1有2528243行
我真的不知道這是什麼意思。誰能告訴我我可能會做錯什麼?
如果您指出left_on在合併=東西,你還必須指出right_on。這僅在您的兩個數據框中的列不具有相同名稱時纔有用。否則,只需使用on = something。 – ysearka