Skip to content

Commit c80d9bf

Browse files
anishkarkianishkarki
authored andcommitted
Refactor: Rename DataFrame variable for non-sequential index
1 parent 937fc33 commit c80d9bf

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

pandas/core/generic.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7801,32 +7801,31 @@ def interpolate(
78017801
1 1.0 2.0 -2.0 5.0
78027802
2 2.0 3.0 -3.0 9.0
78037803
3 2.0 4.0 -4.0 16.0
7804+
Using polynomial interpolation.
7805+
7806+
>>> df["d"].interpolate(method="polynomial", order=2)
7807+
0 1.0
7808+
1 4.0
7809+
2 9.0
7810+
3 16.0
7811+
Name: d, dtype: float64
78047812
78057813
Using index method for linear interpolation
78067814
with non-sequential index.
7807-
>>> data = {"val": [1, np.nan, 3]}
7808-
>>> df = pd.DataFrame(
7815+
>>> data_non_seq = {"val": [1, np.nan, 3]}
7816+
>>> df_non_seq = pd.DataFrame(
78097817
... data, index=[0, 1, 6]
78107818
... ) # a non-sequential index to demonstrate the difference
7811-
>>> df
7819+
>>> df_non_seq
78127820
val
78137821
0 1.0
78147822
1 NaN
78157823
6 3.0
7816-
>>> df["val"].interpolate(method="index").round(1)
7824+
>>> df_non_seq["val"].interpolate(method="index").round(1)
78177825
0 1.0
78187826
1 1.3
78197827
6 3.0
78207828
Name: val, dtype: float64
7821-
7822-
Using polynomial interpolation.
7823-
7824-
>>> df["d"].interpolate(method="polynomial", order=2)
7825-
0 1.0
7826-
1 4.0
7827-
2 9.0
7828-
3 16.0
7829-
Name: d, dtype: float64
78307829
"""
78317830
inplace = validate_bool_kwarg(inplace, "inplace")
78327831

0 commit comments

Comments
 (0)