In [1]:
import pandas as pd
In [2]:
df = pd.DataFrame({'A': [1, 3, 5], 'B': [10, 30, 50], 'C': [100, 300, 500]},
index=pd.date_range('2020-06-01', '2020-06-05', freq='2D'))
print(df)
In [3]:
new_index = pd.date_range('2020-06-01', '2020-06-05', freq='1D')
print(new_index)
In [4]:
print(df.reindex(index=new_index))
In [5]:
print(df.reindex(index=new_index, method='bfill'))
In [6]:
print(df.reindex(index=new_index).interpolate(method='time'))
In [7]:
print(df.reindex(index=['2020-06-01', '2020-06-02', '2020-06-03']))
In [8]:
df2 = pd.DataFrame({'A': [1, 1, 1, 1, 1], 'C': [100, 100, 100, 100, 100]},
index=pd.date_range('2020-06-01', '2020-06-05', freq='D'))
print(df2)
In [9]:
print(df.reindex_like(df2))
In [10]:
print(df.reindex_like(df2).interpolate(method='time'))