1 回答
TA贡献1864条经验 获得超2个赞
import numpy as np
from datetime import datetime,timedelta
import pandas as pd
# make your data a frame
df = 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 object
df['DateTime'] = df['DateTime'].apply(lambda x: datetime(x,1,1))
# create a time range for each day in your period
time_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 gaps
df = af.merge(df, on='DateTime', how='left').interpolate()
print(df)
添加回答
举报