第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Python3 如何打印一條語(yǔ)句,該語(yǔ)句采用從數(shù)據(jù)框派生的值?

Python3 如何打印一條語(yǔ)句,該語(yǔ)句采用從數(shù)據(jù)框派生的值?

慕森王 2023-05-23 14:37:48
我需要幫助打印出一份聲明,該聲明提供夏普比率最高的 A 和 B 各自分配的權(quán)重;這是從數(shù)據(jù)框派生的。到目前為止我做了什么:輸入efficient_df = pd.DataFrame({'Weights_A':weighted_A,                              'Weights_B':weighted_B,                              'Portfolio Return': port_ret,                             'Portfolio Std Dev': port_std,                             'Sharpe Ratio': sharpe_ratio                              })print (efficient_df.head())print('\n')sharpe_highest = efficient_df[efficient_df['Sharpe Ratio'] == efficient_df['Sharpe Ratio'].max()]print('Optimal portfolio details: ')print(sharpe_highest)輸出   Weights_A    Weights_B     Portfolio Return  Portfolio Std Dev  Sharpe Ratio0        0.00        1.00              0.001933          0.017561          0.1100811        0.01        0.99              0.001928          0.017386          0.1109162        0.02        0.98              0.001924          0.017212          0.1117603        0.03        0.97              0.001919          0.017040          0.1126124        0.04        0.96              0.001914          0.016869          0.113472Optimal portfolio details :     Weights_A  Weights_B    Portfolio Return  Portfolio Std Dev  Sharpe Ratio51        0.51        0.49         0.001692            0.01148      0.147348我需要的是這樣的聲明:The best allocation is 0.51 of A and 0.49 of B.但是,下面的代碼沒(méi)有按預(yù)期工作。print('The best allocation is ', weighted_A == efficient_df['Sharpe Ratio'].max(), 'of A and ', weighted_B == efficient_df['Sharpe Ratio'].max(), ' of B.')結(jié)果The best allocation is  False of A and False of B.
查看完整描述

2 回答

?
斯蒂芬大帝

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊

您只是打印布爾值而不是實(shí)際值。

(假設(shè)只有一行具有最大“Srape Ratio”)

sharpe_highest = efficient_df[efficient_df['Sharpe Ratio'] == efficient_df['Sharpe Ratio'].max()]

然后簡(jiǎn)單地打?。?/p>

print('The best allocation is ', float(sharpe_highest.weighted_A), 'of A and ', float(sharpe_highest.weighted_B), ' of B.')



查看完整回答
反對(duì) 回復(fù) 2023-05-23
?
jeck貓

TA貢獻(xiàn)1909條經(jīng)驗(yàn) 獲得超7個(gè)贊

你得到布爾值(False 和 True)而不是你想要的浮點(diǎn)數(shù),因?yàn)槟闶褂谩?=”,它必然返回一個(gè)布爾值。除非我誤解了,否則你不能使用“==”來(lái)獲得你想要的輸出。

print('The best allocation is ', weighted_GS == eff_portfolio_df['Sharpe Ratio'].max(), 'of GS and ', weighted_FB == eff_portfolio_df['Sharpe Ratio'].max(), ' of FB.')


查看完整回答
反對(duì) 回復(fù) 2023-05-23
  • 2 回答
  • 0 關(guān)注
  • 165 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)