擅长:python、mysql、java
<p>使用<code>np.repeat</code>并将结果分配给新列:</p>
<pre><code>arr = np.repeat(X, len(df) // len(X))
df['NewCol'] = pd.Series(arr, index=df.index[:len(arr)])
df
ID FACTOR LEVEL NewCol
0 160 SPM P GAB
1 159 SPM2 S GAB
2 851 ABS K GAB
3 415 ABS P YER
4 202 ABS P YER
5 205 ABS2 Q YER
6 207 AQE T NaN
</code></pre>
<p>如果要填充最后一个NaN,请使用</p>
^{pr2}$