擅长:python、mysql、java
<pre><code>df2 = pd.DataFrame({'foo': ['one','one','two','two','two'],
'bar': [ 'B', 'C', 'A', 'B', 'C'],
'baz': [ 2, 3, 4, 5, 6]},index=['N0001','N0004','N0005','N0006','N0009'])
idx='N'+pd.Series(list(range(1,11))).astype(str).str.zfill(4)
df2.reindex(idx)
Out[365]:
bar baz foo
N0001 B 2.0 one
N0002 NaN NaN NaN
N0003 NaN NaN NaN
N0004 C 3.0 one
N0005 A 4.0 two
N0006 B 5.0 two
N0007 NaN NaN NaN
N0008 NaN NaN NaN
N0009 C 6.0 two
N0010 NaN NaN NaN
</code></pre>