python - How to merge two DataFrames of unequal size based on row value -
i have 2 pandas dataframes of type
dataframe 1 index name property1 property2 0 ("a","b") 1 2 1 ("c","d") 3 4 2 ("e","f") 5 6
and second 1 , has common values , not @ same index ( dont care about).
dataframe 2 index name property3 property4 0 ("g","h") 7 8 1 ("i","j") 9 10 2 ("k","l") 11 12 3 ("a","b") 13 14 4 ("c","d") 15 16 5 ("e","f") 17 18
is there way these combined such resultant dataframe common rows name shared between tables?
i.e result of pandas operation should be
result frame index name property1 property2 property3 property4 0 ("a","b") 1 2 13 14 1 ("c","d") 3 4 15 16 2 ("e","f") 5 6 17 18
sorry not giving actual pandas code create dataframes above. want conceptually understand how join 2 unequal sized dataframes different "indexes" based on column name . tried merge , concat , join dont result want.
a default merge
works fine here, assuming index index:
in [22]: df1.merge(df2) out[22]: name property1 property2 property3 property4 0 ("a","b") 1 2 13 14 1 ("c","d") 3 4 15 16 2 ("e","f") 5 6 17 18
here merge
looks common columns , performs inner
merge on columns.
you can explicit , specify want merge on 'name' column:
df1.merge(df2, on='name')
but in case it's not necessary because common column 'name' anyway.
Comments
Post a Comment