A formula that finds the value in range 1 in range 2 and returns the value in another column at that row position - if-statement

data1
data2
data2
rusult
a
a
apple
apple
c
b
banna
kiwi
b
c
kiwi
banna
c
kiwi
a
apple
a
apple
b
banna
c
kiwi
Find the first value 'a' in data2.
Using the found row position as the index, find the value of the second column of data2.
Record in result.
Repeat process. I want to make this work as a formula!

use:
=INDEX(IFNA(VLOOKUP(AF5:AF; AH:AI; 2; )))

Related

How to compare rows within the same dataframe and create a new column for similar rows

obj_id
Column B
Colunm C
a1
cat
bat
a2
bat
man
r1
man
apple
r2
apple
cat
The orignal dataframe (above) is called df
I am trying to make a new colunm called new_obj_id where if rows in column B match any row of col C the new_obj_id should then have values of obj_id that match col B
obj_id
Column B
Colunm C
new_obj_id
a1
cat
bat
a2
a2
bat
man
r1
r1
man
apple
r2
r2
apple
cat
a1
This is the expected table
This is what I tried but couldn't get through:
dataframe1['new_obj_id'] = dataframe1.apply(lambda x: x['obj_id']
if x['Column_B'] in x['Column C']
else 'none', axis=1)
Try this:
df['new_obj_id'] = df['Column C'].map(dict(zip(df['Column B'],df['obj_id'])))
Output:
0 a2
1 r1
2 r2
3 a1

Regextmatch + partial vlookup in google spreadsheets

I have a table with three columns in google sheets:
Column A (raw data): it containss different strings for which I need to extract the character "Y" + a match with a string in columns B.
-Columns B: is an unordered list of codes that can occur multiple times as a substring in column A
Column C displays the expected outcome.
Column A (raw data):
Row 1: X Y Apple
Row 2: Z Apple
Row 3: K
Row 4: L M Y Orange
Column B (codes to match, unordered):
Row 1: Apple
Row 2: Orange
Row 3: Mango
Row 4: Banana
Column C (expected outcome):
Row 1: Y Apple
Row 2: Apple
Row 3: (empty cell)
Row 4: Y Orange
I'm not 100% clear on what you need, but is it this in cell C1?
=arrayformula(trim(if(regexmatch(A1:A,"Y "),"Y ",)&if(countif(B:B,iferror(regexextract(A1:A,"\ (\w+)$")))>=1,iferror(regexextract(A1:A,"\ (\w+)$")),)))

Combine list A value 0 to list B value 0: Python

Hi I have 2 list from a from a loop.
A = [basket,fridge,table,basket,fridge]
B = [banana, apple, grapes, apple, banana]
Is there a way for me to format it as:
c = [basket:banana, fridge:apple, table:grapes, basket:apple, fridge:banana]
or
c = [basket, banana, fridge, apple, table, grapes, basket, apple, fridge, banana]
My goal would be to list how many bananas in basket; bananas in fridge and so on.
zip in Python can give you result you want:
e.g. c = zip(a, b), c will contain [(basket,banana), (fridge,apple), (table,grapes), (basket,apple), (fridge,banana)]

3 column excel find value cell b2 in column a replace with cell c2

using 3 columns 100k down column "a:a"= part desc with part number y400cc(webpage title) cell "b1"=old part number y400cc "c1"=new part number wpy400cc.
*****Find cell b2 in column a and replace with cell c2 ?***
I am not Sure I understood your question fully. But here is my proposal:
Column A contains some text (Example: CELL A2 = "xx456yy")
Column B contains a part number which may or may not be found in A (Example CELL B2 = "456")
Column C contains the new part number (Example: CELL C2 = "900")
Column D to have the following formula, which will replace the Column B text found in Column A, with Column C text:
=IF(IFERROR(FIND(B2,A2),1)<>1,REPLACE(A2,FIND(B2,A2),LEN(B2),C2),"")

Stata - Creating a set of all possible unmatched pairs

I have observational data of observed matched pairs (supplier-buyer) which I would like to use to build a set of counterfactual observations.
Suppose we observe two suppliers (X and Y) and 3 buyers (A, B, and C).
We observe that supplier X has a $2M contract with buyer A, and a $5M contract with buyer B.
We also observe that supplier Y has only one contract with buyer C worth $4M.
I would like to build a set of counterfactuals based on the set of unmatched pairs. I want to place a hypothetical contract value for each counterfactual observation that is equal to the maximum of what each party contracted at in the observed data. For example, this is what we would get for the counterfactuals based on the observations above:
Counterfactual observation #1: X with C for a value of $5M (because X has $5M for his observed largest contract and C has $4M, $5M is higher)
Counterfactual observation #2: Y with A for a value of $4M (because Y has $4M for his observed largest contract and A has $2M, $4M is higher)
Counterfactual observation #3: Y with B for a value of $5M (because Y has $4M for his observed largest contract and B has $5M, $5M is higher)
and here's the Stata sample code depicting my data..
clear
input str3(supplier buyer) float cont_value
"X" "A" 2
"X" "B" 5
"Y" "C" 4
end
clear
set more off
input str3(supplier buyer) value
"X" "A" 2
"X" "B" 5
"Y" "C" 4
end
list
fillin supplier buyer
list, sepby(supplier)
bysort supplier : egen maxsupp = max(value)
bysort buyer : egen maxbuy = max(value)
egen value2 = rowmax(max*) if _fillin
replace value2 = value if !_fillin
sort supplier buyer
order value2, after(value)
list, sepby(supplier)
In addition to the answer on Statalist which merges a series of datasets, you can achieve this with fillin.
clear *
input str3(supplier buyer) float cont_value
"X" "A" 2
"X" "B" 5
"Y" "C" 4
end
fillin supplier buyer
list
tempvar cont_val cont_val1
by supplier, sort : egen `cont_val' = max(cont_value)
by buyer, sort : egen `cont_val1' = max(cont_value)
egen cont_val = rowmax(`cont_val' `cont_val1') if _fillin
replace cont_val = cont_value if !_fillin
drop _fillin
sort supplier buyer
list supplier buyer cont_value cont_val