擅长:python、mysql、java
<p>如果每行最多只有一个<code>1.0</code>,则可以使用此处描述的函数查找与<code>1.0</code>匹配的列来创建新的数据帧:</p>
<p><a href="https://stackoverflow.com/questions/14734695/get-column-name-where-value-is-something-in-pandas-dataframe">Get column name where value is something in pandas dataframe</a></p>
<pre><code>cols['column'] = df.apply(lambda x: df.columns[x.argmax()], axis = 1)
</code></pre>
<p>把它转换成<code>dict</code><code>d_cols</code>。你知道吗</p>
<p>然后,您可以在刚刚创建的<code>dict</code>的帮助下替换列的名称:</p>
<pre><code>df.rename(d_cols)
</code></pre>