Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Python loc multiindex series with repeated keys

$
0
0

I have a multi-index Series defined like this:

s = pd.Series([1, 2, 3, 4, 5, 6],    index=pd.MultiIndex.from_product([["A", "B"], ["c", "d", "e"]]))s
A  c    1   d    2   e    3B  c    4   d    5   e    6dtype: int64

I want to evaluate this series at two lists:

l1 = ['A', 'B', 'A']l2 = ['c', 'd', 'c']

How can I do it pythonically without a for loop, e.g. without

[s.loc[x, y] for x, y in zip(l1, l2)]

Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>