Skip to content

Commit 937fc33

Browse files
anishkarkianishkarki
authored andcommitted
Fix: Use index method for linear interpolation with non-sequential index
1 parent cefadad commit 937fc33

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

pandas/core/generic.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7802,7 +7802,8 @@ def interpolate(
78027802
2 2.0 3.0 -3.0 9.0
78037803
3 2.0 4.0 -4.0 16.0
78047804
7805-
Using linear and index method for linear interpolation.
7805+
Using index method for linear interpolation
7806+
with non-sequential index.
78067807
>>> data = {"val": [1, np.nan, 3]}
78077808
>>> df = pd.DataFrame(
78087809
... data, index=[0, 1, 6]
@@ -7812,16 +7813,12 @@ def interpolate(
78127813
0 1.0
78137814
1 NaN
78147815
6 3.0
7815-
>>> df.interpolate(method="linear")
7816-
val
7817-
0 1.0
7818-
1 2.0
7819-
6 3.0
7820-
>>> df.interpolate(method="index").round(1)
7821-
val
7822-
0 1.0
7823-
1 1.3
7824-
6 3.0
7816+
>>> df["val"].interpolate(method="index").round(1)
7817+
0 1.0
7818+
1 1.3
7819+
6 3.0
7820+
Name: val, dtype: float64
7821+
78257822
Using polynomial interpolation.
78267823
78277824
>>> df["d"].interpolate(method="polynomial", order=2)

0 commit comments

Comments
 (0)