One solution would be to use pandas.DataFrame.apply. But is there a more efficient way?+ In the following pattern is applied in the examples: AA = 0.0, AB = 0.5, BB = 1.0.
Input Table
Index | Col1 | Col2 |
---|---|---|
Sample1 | AB | BB |
Sample2 | AA | AB |
Output Table
Index | Col1 | Col2 |
---|---|---|
Sample1 | 0.5 | 1.0 |
Sample2 | 0.0 | 0.5 |
import pandas as pd
table_input = pd.DataFrame({'Col1': ["AB", "BB"],
'Col2': ["AA", "AB"]},
index=['Sample1', 'Sample2'])
table_output = pd.DataFrame({'Col1': [0.5, 1.0],
'Col2': [0.0, 0.5]},
index=['Sample1', 'Sample2'])
# Please insert solution here...