I have lists inside list where I want to create a new column in my dataframe for each list:
My input can be seen below:
datalist : [[abc1, abc2, abc3, abc4, abc5],[kh1, kh2, kh3, kh4],[jpor1, jpor2, jpor3, jpor4, jpor5]]
Each item in my datalist
is a column title in my existing dataframe
while each index is also a column in my dataframe which contains the number where I need to extract the value for my new column.
So I want my output to be something like this:
index abc1 abc2 abc3 abc4 abc5 abc_result
4 87 94 34 28 43 28
2 87 94 34 28 43 94
5 87 94 34 28 43 43
4 87 94 34 28 43 28
1 87 94 34 28 43 87
Because I have 3 lists inside my datalist, I want to have 3 new columns created and added to the dataframe, which are abc_result
, kh_result
, jpor_result
(all based from the index column). I am really confused as I feel I need to make a new list in for every list in my datalist while string formatting the new column title?
So basically the new column value is based on the index column's value. If the value is 1 I want to extract the value from abc1 for abc_result, if 2 then extract the value from abc2, etc. Then another new column for kh_result which also need the value from the kh1/kh2/kh3 based on the index column value.