May-09-2018, 09:53 PM
The problem I see is that your paraList is not really a data frame as it has only one row... so looks like it is going to work better as a dictionary:
Remember also to add guards for the cases when a column is only in one of the tables... for example in this code a column only in datapara will raise an exception.
datapara.iloc[0].to_dict()
Output:{'A': 'Y', 'C': 'N', 'E': 'Y', 'F': 'Y'}
Now it is easy to create a selector for the columns that has value 'Y'selection = datapara.iloc[0].to_dict() cols = [c for c in selection if selection[c] == 'Y'] print(dataRaw[cols])
Output: A E F
0 0 3.2 1.6
1 1 3.2 1.6
2 2 6.5 1.9
3 0 3.2 1.6
4 1 6.5 1.9
5 4 3.2 1.6
To select the ones with 'N', you can use a similar process.Remember also to add guards for the cases when a column is only in one of the tables... for example in this code a column only in datapara will raise an exception.