Tuesday, 15 September 2015

python - pandas: how to merge 2 dataframes on 'X' from df1 and f['Y'] from df2 -



python - pandas: how to merge 2 dataframes on 'X' from df1 and f['Y'] from df2 -

i want merge 2 dataframes df1 , df2, using left_on: col 'x' df1, using right_on: result of function f apply col 'y' df2.

i may create specific columns 'z' result of f(df2['y']) , want avoid it.

is possible ?

you can pass left_on , right_on arguments merge:

in [11]: df1 = pd.dataframe([[1, 3], [2, 4]], columns=["x", "a"]) in [12]: df2 = pd.dataframe([[1, 5], [2, 6]], columns=["z", "b"]) in [13]: df1.merge(df2, left_on=["x"], right_on=["z"]) out[13]: x z b 0 1 3 1 5 1 2 4 2 6

python pandas

No comments:

Post a Comment