擅长:python、mysql、java
<p>我相信需要<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Index.get_indexer.html" rel="nofollow noreferrer">^{<cd1>}</a>通过过滤的列名称查找位置,对于索引是可能的,使用相同的方法或使用{a2}通过布尔掩码查找位置:</p>
<pre><code>df = pd.DataFrame({'timestamp':list('abadef'),
'B':[4,5,4,5,5,4],
'C':[7,8,9,4,2,3],
'D':[1,3,5,7,1,0],
'E':[5,3,6,9,2,4]}, index=list('ABCDEF'))
print (df)
timestamp B C D E
A a 4 7 1 5
B b 5 8 3 3
C a 4 9 5 6
D d 5 4 7 9
E e 5 2 1 2
F f 4 3 0 4
idxlbls = df.index[df['timestamp'] == 'a']
stuff = df.loc[idxlbls, 'C':'E']
print (stuff)
C D E
A 7 1 5
C 9 5 6
a = df.index.get_indexer(stuff.index)
</code></pre>
<p>或通过布尔掩码获取位置:</p>
^{pr2}$
<hr/>
<pre><code>b = df.columns.get_indexer(stuff.columns)
print (b)
[2 3 4]
</code></pre>