In [1]:
import pandas as pd
In [2]:
df = pd.DataFrame({'col1': [0, pd.np.nan, pd.np.nan, 3, 4],
'col2': [pd.np.nan, 1, 2, pd.np.nan, pd.np.nan],
'col3': [4, pd.np.nan, pd.np.nan, 7, 10]})
In [3]:
print(df)
In [4]:
print(df.interpolate())
In [5]:
print(df.interpolate(axis=1))
In [6]:
print(df.interpolate(limit=1))
In [7]:
print(df.interpolate(limit=1, limit_direction='forward'))
In [8]:
print(df.interpolate(limit=1, limit_direction='backward'))
In [9]:
print(df.interpolate(limit=1, limit_direction='both'))
In [10]:
print(df.interpolate(limit_direction='both'))
In [11]:
print(df.interpolate(limit_area='inside'))
In [12]:
print(df.interpolate(limit_area='outside'))
In [13]:
print(df.interpolate(limit_area='outside', limit_direction='both'))
In [14]:
df_copy = df.copy()
df_copy.interpolate(inplace=True)
print(df_copy)
In [15]:
s = pd.Series([0, pd.np.nan, pd.np.nan, pd.np.nan, 4, pd.np.nan, pd.np.nan],
index=[0, 2, 5, 6, 8, 10, 14])
print(s)
In [16]:
print(s.interpolate())
In [17]:
print(s.interpolate('index'))
In [18]:
print(s.interpolate('values'))
In [19]:
s.index = list('abcdefg')
print(s)
In [20]:
print(s.interpolate())
In [21]:
# print(s.interpolate('values'))
# TypeError: Cannot cast array data from dtype('O') to dtype('float64') according to the rule 'safe'
In [22]:
s = pd.Series([0, 10, pd.np.nan, pd.np.nan, 4, pd.np.nan, pd.np.nan],
index=[0, 2, 5, 6, 8, 10, 14])
In [23]:
print(s.interpolate('spline', order=2))
In [24]:
s.index = range(7)
In [25]:
print(s.interpolate('spline', order=2))
In [26]:
s.index = list('abcdefg')
In [27]:
# print(s.interpolate('spline', order=2))
# TypeError: unsupported operand type(s) for -: 'str' and 'str'