我正在尝试使用存储在单独数据框中的价格更新头寸数据框。我想将最新价格放入“ last_price”列中,并将该价格的数据放入“ last_date”列中。
import datetime
from scipy import stats
import numpy as np
import pandas as pd
df_portfolio = pd.DataFrame({ 'amount' : np.random.randint(low=0, high=10, size=(4)),
'timestamp' : pd.Timestamp('20130102'),
'exch' : pd.Categorical(["e1","e1","e2","e2"]),
'token' : pd.Categorical(["BTC","ETH","ETH","LTC"])
})
df_ETH_price = pd.DataFrame({
'date': ('2018-08-11','2018-08-12','2018-08-13'),
'price' : (322.11,319.57,286.50)
})
df_portfolio['last_price'] = np.nan
df_portfolio['last_date'] = "?"
print(df_portfolio)
print (df_ETH_price)
预期结果如下:
amount exch timestamp token last_price last_date
0 7 e1 2013-01-02 BTC NaN ?
1 4 e1 2013-01-02 ETH 286.50 2018-08-13
2 2 e2 2013-01-02 ETH 286.50 2018-08-13
3 9 e2 2013-01-02 LTC NaN ?
一只名叫tom的猫
相关分类