How does df.interpolate(inplace=True) function?

813 Views Asked by At

I am having trouble understanding how this functions. With inplace=True, the function doesn't output anything and the original df remains unchanged. How does this work?

So sorry I wrote 'filter' in my first post. That was very stupid mistake.

As @Alex requested, the example is as follows:

df = pd.DataFrame(np.random.randn(4,3), columns=map(chr, range(65,68)))
df['B'] = np.nan
print df
print df.interpolate(axis=1)
print df
print df.interpolate(axis=1, inplace=True)
print df

The output is as follows:

     A       B         C
0 -0.956273 NaN  0.919723
1  1.127298 NaN -0.585326
2 -0.045163 NaN -0.946355
3 -1.375863 NaN -1.279663

      A         B         C
0 -0.956273 -0.018275  0.919723
1  1.127298  0.270986 -0.585326
2 -0.045163 -0.495759 -0.946355
3 -1.375863 -1.327763 -1.279663

      A   B         C
0 -0.956273 NaN  0.919723
1  1.127298 NaN -0.585326
2 -0.045163 NaN -0.946355
3 -1.375863 NaN -1.279663

None

      A   B         C
0 -0.956273 NaN  0.919723
1  1.127298 NaN -0.585326
2 -0.045163 NaN -0.946355
3 -1.375863 NaN -1.279663

As you can see, the first interpolation created a copy of the original dataframe. What I wanted is to interpolate and update the original dataframe, so I tried inplace since the documentation states the follow:

inplace : bool, default False Update the NDFrame in place if possible.

The second interpolation did not return any value, and it did not update the original dataframe. So I'm confused.

And as @joris requested, my pandas version is '0.15.1'. Though this request is due to my mistake...

0

There are 0 best solutions below