I am just wondering Can i use contains with 2 DataFrames? like grep in R. When i use merge() or join(), the row makes duplicated. this is for the example
For example
df1 = pd.DataFrame({'id':[1,2,3],'name':['hayley','jack','may'],'class':['H','M','S']})
df1
| id | name | class |
|---|---|---|
| 1 | hayley | H |
| 2 | jack | M |
| 3 | may | S |
df2 = pd.DataFrame({'number1':[4,5,6],'name1':['cat','chang','jason'],'class1':['H','H','S']})
df2
| id1 | name1 | class1 |
|---|---|---|
| 4 | cat | H |
| 5 | chang | H |
| 6 | jason | S |
and i want to match df1['class'] and df2['class1']. if the class, class1 rows has same word, concat. if not null.
sorry for my English. i don't really know how to explain it....
this is what i want to make it!!
| id | name | class | id1 | name1 | class1 |
|---|---|---|---|---|---|
| 1 | hayley | H | |||
| 2 | jack | M | |||
| 3 | may | S | 6 | json | S |
however, if use merge()
pd.merge(df1,df2,left_on='class', right_on='class1', how='left')
| id | name | class | id1 | name1 | class1 |
|---|---|---|---|---|---|
| 1 | hayley | H | 4 | cat | H |
| 1 | hayley | H | 4 | chang | H |
| 2 | jack | M | |||
| 3 | may | S | 6 | json | S |
i want to know how to make that without duplicate. plese help :'(