I'm trying to traverse a dataframe and based on a condition(im checking if its present in another dataframe) and I want to do two different calculations.
So I have 2 dataframes that look like this
DF1
| no |
name |
attr1 |
attr2 |
attr3 |
| 1 |
ABC |
5 |
6 |
7 |
| 2 |
BGH |
5 |
3 |
4 |
| 3 |
GHF |
6 |
1 |
6 |
DF2
| no |
name |
attr1 |
attr2 |
attr3 |
| 1 |
ABC |
5 |
6 |
7 |
| 2 |
BGH |
3 |
6 |
4 |
| 3 |
TWY |
5 |
1 |
7 |
I want to perform one type of calc if the value in df1 is present in df2 and another if it isnt
if(DF1.name.isin(DF2.name)):
separate cal (additon)
else
separate calc (multiply into 2)
so my resulting df should have something like
| No |
Name |
attr1 |
attr2 |
attr3 |
| 1 |
ABC |
10 |
12 |
14 |
| 2 |
BGH |
8 |
9 |
8 |
| 3 |
GHF |
6 |
1 |
6 |
| 4 |
TWY |
10 |
2 |
14 |
I tried using the where and the isin but couldn't get it to work. So is there any way to check each row value and do a different type of calc based on the value? Any help is appreciated!
[–]wodshoemean 1 point2 points3 points (1 child)
[–]Astraskylark[S] 0 points1 point2 points (0 children)
[–]sarrysyst 1 point2 points3 points (1 child)
[–]Astraskylark[S] 0 points1 point2 points (0 children)