I have a dataframe x:
x = pd.DataFrame(np.random.randn(3,3), index=[1,2,3], columns=['A', 'B', 'C'])
x
A B C
1 0.256668 -0.338741 0.733561
2 0.200978 0.145738 -0.409657
3 -0.891879 0.039337 0.400449
and I would like to select a bunch of index column pairs to populate a new Series. For example, I could select [(1, A), (1, B), (1, A), (3, C)] which would generate a list or array or series with 4 elements:
[0.256668, -0.338741, 0.256668, 0.400449]
Any idea of how I should do that?
Use ix should be able to locate the elements in the data frame, like this:
If your pairs are positions instead of index/column names,
Or get the position from
np.searchsorted
I think
get_value()
andlookup()
is faster: