我有df
和endDate
列,我想用它作为我的x
数组和discountFactor
列作为y
数组。目标是使用三次样条方法在x数组范围内的某个日期内插值discountFactor
,比如2020-12-31
源代码df
如下:
lst = [['6M', '2020-10-26', '2021-04-26', '-0.521684','1.002611'], ['1Y', '2020-10-26', '2021-10-26', '-0.534855','1.005377'],
['5Y', '2020-10-26', '2025-10-27','-0.495927','1.025184']]
df = pd.DataFrame(lst, columns =['tenor', 'startDate', 'endDate','ratePercent','discountFactor'], dtype = float)
请参阅以下步骤,不幸的是,这些步骤导致了所有df
列的NaN
,即使在我知道discountFacor
值的地方也是如此
# Converting date column strings to date objects
df['endDate'] = pd.to_datetime(df['endDate'], format='%Y-%m-%d')
df['startDate'] = pd.to_datetime(df['startDate'], format='%Y-%m-%d')
# Setting endDate column as my index
df.set_index("endDate", inplace= True)
# Creating daily dates range between start and end dates from the df
dates_range = pd.date_range(start='2020-10-26', end='2025-10-27')
idx = pd.DatetimeIndex(dates_range)
df = df.reindex(idx)
目前没有回答
相关问题 更多 >
编程相关推荐