擅长:python、mysql、java
<p>如果需要按<code>isupper</code>检查所有列的测试值,并将不匹配的值替换为<code>NaN</code>,这样就可以用<code>iloc</code>来填充缺少的值并查看第一列:</p>
<pre><code>df = df.where(df.applymap(lambda x: x.isupper())).bfill(axis=1).iloc[:, 0].to_frame('col')
print (df)
col
0 SEQ
1 LCALC
2 LCALC
3 RYR
</code></pre>
<p>编辑:</p>
<p>按匹配值的位置用列创建<code>df1</code>,因此第一列是第一个上限值,…:</p>
<pre><code>#reshape by stack, None and NaNs columns are removed,
#remove second level of MultiIndex
s = df.stack().reset_index(level=1, drop=True)
#filter only upper values, convert to DataFrame
df1 = s[s.str.isupper()].rename_axis('idx').reset_index(name='val')
#create counter column for count first, second... columns
df1['g'] = df1.groupby('idx').cumcount()
#reshape by pivot and if necessary add non upper rows
df1 = df1.pivot('idx','g','val').reindex(df.index)
print (df1)
g 0 1
0 SEQ LTOTAL
1 LCALC NaN
2 LCALC NaN
3 RYR LTOTAL
first = df1[0].to_frame('col')
second = df1[1].to_frame('col')
print (first)
col
0 SEQ
1 LCALC
2 LCALC
3 RYR
print (second)
col
0 LTOTAL
1 NaN
2 NaN
3 LTOTAL
</code></pre>