I have a DataFrame in this format:
a b c
0 1 2 3
1 4 5 6
2 7 8 9
3 10 11 12
4 13 14 15
and an array like this with column names:
['a', 'a', 'b', 'c', 'b']
and Im hoping to extract an array of data, one from each row. An array of column names indicates which column I want from each row. Here is the result:
[1, 4, 8, 12, 14]
Is this possible as a single command with Pandas, or do I need to iterate? I tried using indexing
i = pd.Index(['a', 'a', 'b', 'c', 'b'])
i.choose(df)
but I have a segfault that I could not diagnose because the documentation is not enough.
source
share