2017-01-23 29 views
21

मैं दो स्तंभों का उपयोग फ्रेम दो पांडा डेटा में शामिल होने की कोशिश कर रहा हूँ:पांडा: विलय (शामिल होने) एकाधिक स्तंभों पर दो डेटा फ्रेम

new_df = pd.merge(A_df, B_df, how='left', left_on='[A_c1,c2]', right_on = '[B_c1,c2]') 

लेकिन निम्न त्रुटि मिला:

pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:4164)() 

pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:4028)() 

pandas/src/hashtable_class_helper.pxi in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13166)() 

pandas/src/hashtable_class_helper.pxi in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13120)() 

KeyError: '[B_1, c2]' 

किसी भी विचार ऐसा करने का सही तरीका क्या होना चाहिए? धन्यवाद!

+9

'left_on' और' right_on' की कोशिश करें, एक स्ट्रिंग है एक सूची की तरह लग रहा स्ट्रिंग की एक सूची नहीं होना चाहिए। – root

उत्तर

51

इस

new_df = pd.merge(A_df, B_df, how='left', left_on=['A_c1','c2'], right_on = ['B_c1','c2']) 

http://pandas.pydata.org/pandas-docs/version/0.19.1/generated/pandas.DataFrame.merge.html

left_on : label or list, or array-like Field names to join on in left DataFrame. Can be a vector or list of vectors of the length of the DataFrame to use a particular vector as the join key instead of columns

right_on : label or list, or array-like Field names to join on in right DataFrame or vector/list of vectors per left_on docs

संबंधित मुद्दे