亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Python 中合并兩個數據幀,將日期從一個數據幀線性插值到另一個數據幀

在 Python 中合并兩個數據幀,將日期從一個數據幀線性插值到另一個數據幀

慕村225694 2022-01-11 19:35:05
我有 2 個不同的數據框。一個是具有日期和值的“值”列表。第二個數據框是日期數據框,位于數據框 1 的日期之間。我想合并 2 個數據框并將數據框 1 中的值插入數據框 2 中的值。我嘗試了以下方法:sample_final= sample_set_1.merge(sample_set_2, how='right').set_index('Maturity').interpolate()但它不起作用!我在一個循環中轉來轉去!任何幫助表示贊賞!謝謝成熟度2019-04-11 1.02019-04-12 0.9999332019-04-15 0.9997322019-04-16 0.99966499999999992019-04-23 0.99919699999999992019-04-29 0.99879599999999992019-05-06 0.99832900000000012019-05-15 0.99772900000000012019-06-17 0.9955322019-07-15 0.993692019-08-15 0.9916632019-09-16 0.9895822019-10-15 0.9877252019-11-15 0.9857642019-12-16 0.983832020-01-15 0.98198999999999992020-02-18 0.9799352020-03-16 0.97832099999999992020-04-15 0.976552020-07-15 0.9713532020-10-15 0.966312021-04-15 0.95686100000000012022-04-19 0.9382632023-04-17 0.91982024-04-15 0.9006190000000001
查看完整描述

1 回答

?
慕尼黑的夜晚無繁華

TA貢獻1864條經驗 獲得超6個贊

假設您想在當天線性插值:


df.Maturity = pd.to_datetime(df.Maturity)

df2.Maturity = pd.to_datetime(df2.Maturity)


# get the common date in the two data frames

common = df.merge(df2.drop_duplicates(), how='outer').set_index('Maturity')


# interpolate the value:

common = common.resample('d').interpolate().reset_index()


# merge

common.merge(df2, how='right')


查看完整回答
反對 回復 2022-01-11
  • 1 回答
  • 0 關注
  • 154 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號