Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python dfply package - Joins

Tags:

python

dfply

Coming from R and trying to simulate dplyr with dfply package in Python. Need some help.

I have two questions here and please help.

  1. How I join two datasets if those join columns have different names?
  2. Is there way I join more than column? As per documentatioon, I can join by only one column.

https://github.com/kieferk/dfply#joining

I like dfply package but it is lacking critical functionality. Thanks for your help. Or help me any other packages in Python like R dplyr

like image 885
Murali Avatar asked Aug 21 '26 01:08

Murali


1 Answers

dfply package is build on the great pandas package in python. Its documentation serves mostly to guide you towards its underlying functionalities. If you go to its github repo and find the join.py file you can see the underlying implementation of various joins relies on df.merge function of pandas.

so to answer your questions (hopefully it is not too late):

  1. How I join two datasets if those join columns have different names?

    df>> inner_join(other, by=('A_c1','B_c1'))
    
  2. Is there way I join more than column? As per documentatioon, I can join by only one column.

    df>> inner_join(other, by=[('A_c1','B_c1'),('A_c2','B_c2')])
    

one thing I need to add is, at the time of this writing, Oct 2018, you have to install the develop version of the package, which have the multi-column join functionality added.

like image 93
PaulDong Avatar answered Aug 22 '26 16:08

PaulDong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!