およびキーワードを使用fillna
して、DataFrame と Series を埋めようとしています。を含めない場合は が尊重されますが、制限を含めるとすぐに尊重されなくなります。以下は、DataFrame を使用した例です。value
limit
limit
value
value
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randn(5, 3), index=['a', 'c', 'e', 'f', 'h'],columns=['one', 'two','three'])
df2 = df.reindex(['a', 'b', 'c', 'd', 'e', 'f', 'g','h','i', 'j','k'])
In [7]: df2
Out[7]:
one two three
a -0.942695 0.465658 -0.966754
b NaN NaN NaN
c -1.208036 0.287274 -1.116466
d NaN NaN NaN
e 0.041212 0.065966 -1.895570
f 0.869104 -3.481962 -0.280699
g NaN NaN NaN
h -1.151732 -0.310296 -1.701202
i NaN NaN NaN
j NaN NaN NaN
k NaN NaN NaN
In [8]: df2.fillna(method='pad', limit=1)
Out[8]:
one two three
a -0.942695 0.465658 -0.966754
b -0.942695 0.465658 -0.966754
c -1.208036 0.287274 -1.116466
d -1.208036 0.287274 -1.116466
e 0.041212 0.065966 -1.895570
f 0.869104 -3.481962 -0.280699
g 0.869104 -3.481962 -0.280699
h -1.151732 -0.310296 -1.701202
i -1.151732 -0.310296 -1.701202
j NaN NaN NaN
k NaN NaN NaN
In [9]: df2.fillna(value=999,method='pad', limit=1)
Out[9]:
one two three
a -0.942695 0.465658 -0.966754
b 999.000000 999.000000 999.000000
c -1.208036 0.287274 -1.116466
d 999.000000 999.000000 999.000000
e 0.041212 0.065966 -1.895570
f 0.869104 -3.481962 -0.280699
g 999.000000 999.000000 999.000000
h -1.151732 -0.310296 -1.701202
i 999.000000 999.000000 999.000000
j 999.000000 999.000000 999.000000
k 999.000000 999.000000 999.000000
ここで何かが足りないのですか、それともバグですか?
乾杯
編集:python 2.7でnumpy 1.6.1でpandas 0.8.1を使用する