慕斯王
import numpy as npfrom datetime import datetime,timedeltaimport pandas as pd# make your data a framedf = pd.DataFrame([[2020, 713000], [ 2019, 703000], [ 2018, 694000], [ 2017, 684000], [ 2016, 674000], [ 2015, 664000], [ 2014, 655000], [ 2013, 645000], [ 2012, 636000], [ 2011, 627000]], columns=['DateTime','pop'])# make DateTime column an datetime objectdf['DateTime'] = df['DateTime'].apply(lambda x: datetime(x,1,1))# create a time range for each day in your periodtime_range = np.arange(datetime(2011, 1,1), datetime(2021,1,1), timedelta(days=1))# make time_range a frame af = pd.DataFrame(time_range, columns=['DateTime'])# merge both together (left join on column DateTime) and interpolate the gapsdf = af.merge(df, on='DateTime', how='left').interpolate()print(df)