I have the following:
dictionary = {'col1': ["England", "USA","Germany","Canada","Cuba","Vietnam"], 'col2':
["France", "Spain","Italy","Jamaica","Bulgaria","South Korea"],
"rating":[2,4,-5,2,1,2],"value":[1,1,2,2,3,3]}
table=pd.DataFrame(dictionary)
which results in the following output:
col1 col2 rating value
0 England France 2 1
1 USA Spain 4 1
2 Germany Italy -5 2
3 Canada Jamaica 2 2
4 Cuba Bulgaria 1 3
5 Vietnam South Korea 2 3
Separately I have a list of three series.
list([pd.Series([50,2],["const","Match Rating"]),
pd.Series([48,2],["const","Match Rating"]),
pd.Series([47,2.5],["const","Match Rating"])])
which looks like that
[const 50
Match Rating 2
dtype: int64,
const 48
Match Rating 2
dtype: int64,
const 47
Match Rating 2.5
dtype: int64]
I want to create a column in the data frame called "result" where a formula is applied. Rating (from the dataframe) * match rating (from the list) + const (from the list)
When "value" in dataframe is 1 the first set of elements from the list should be applied, i.e. 50 and 2. When "value" from dataframe is 2 the second set of elements should be applied, i.e. 48 and 2 and so forth.
Desired result is like that:
col1 col2 rating value result
England France 2 1 54
USA Spain 4 1 58
Germany Italy -5 2 38
Canada Jamaica 2 2 52
Cuba Bulgaria 1 3 49.5
Vietnam South Korea 2 3 52
Thanks in advance