我从两个这样的字典中创建了一个框架
import pandas as pd
summary={'BTC': {'DAE': -11661300, 'Vega': -661, 'Theta': 109, 'Gamma': -32391},
'ETH': {'DAE': -533985, 'Vega': -227, 'Theta': 518, 'Gamma': -289779}}
summary_df = pd.DataFrame.from_dict(summary)
summary_df = summary_df.transpose()
display(summary_df)
greeks_6_pm= {'BTC': {'DAE': -11725765, 'Vega': -567, 'Theta': 79, 'Gamma': 85512},
'ETH': {'DAE': -676607, 'Vega': -15, 'Theta': 186, 'Gamma': -78159}}
change_of_greeks_df = pd.DataFrame(summary).sub(pd.DataFrame(greeks_6_pm)).transpose().add_prefix("△")
pnl_summary = pd.merge(summary_df, change_of_greeks_df, left_index=True, right_index=True)
字符串
我得到的输出像
DAE Vega Theta Gamma △DAE △Vega △Theta △Gamma
BTC -11661300 -661 109 -32391 64465 -94 30 -117903
ETH -533985 -227 518 -289779 142622 -212 332 -211620
型
但我需要输出像
Currency Dae Vega theta gamma
BTC -11661300 -661 109 -32391
△BTC 64465 -94 30 -117903
ETH -533985 -227 518 -289779
△ETH 142622 -212 332 -211620
型
尝试了
pnl_summary = pd.concat([summary_df, change_of_greeks_df], axis=0, keys=['', 'Changed']).swaplevel(axis=0)
display(pnl_summary)
型
但是得到的输出
DAE Vega Theta Gamma △DAE △Vega △Theta △Gamma
BTC -11,661,300 -661 109 -32,391 nan nan nan nan
ETH -533,985 -227 518 -289,779 nan nan nan nan
BTC Changed nan nan nan nan 64,465 -94 30 -117,903
ETH Changed nan nan nan nan 142,622 -212 332 -211,620
型
如何在JavaScript中获得所需的输出
1条答案
按热度按时间vojdkbi01#
给您:
字符串