擅长:python、mysql、java
<p>熊猫是一个伟大的工具。我会这样做:</p>
<pre><code># create some similar data
import pandas as pd
df = pd.DataFrame({'Phase': ['1PH', '3PH', '3PH', '1PH'], 'kVA': [50, 750, 300, 37.5]})
# add a new column (some elements will not change)
df['Line'] = df['Phase']
# modify rows that fit your criteria
df.loc[ (df.kVA < 750) & (df.Phase == '3PH'), 'Line'] += 'SM'
df.loc[ (df.kVA >= 750) & (df.Phase == '3PH'), 'Line'] += 'LG'
</code></pre>
<p><code>.loc</code>和<code>iloc</code>非常适合过滤数据帧的一部分</p>
<p>注意:我正在使用Pandas v0.20.3进行此测试</p>