【发布时间】:2018-07-18 17:54:28
【问题描述】:
def priceusd(df):
return df['closeprice'][-1]*btcusdtclose[-1]
此函数使用数据框作为参数,通过将其比特币价格乘以比特币美元价格,得出以美元计价的资产价格。
我想要做的只是让资产的名称成为参数,而不是价格数据来自的数据框。我所有的数据框都被命名为assetbtc。例如 ethbtc 或 neobtc。我希望能够将 eth 传递给函数并返回 ethbtc['closeprice'][-1]*btcusdtclose[-1]。
例如,
def priceusd(eth):
return ethbtc['close'][-1]*btcusdtclose[-1]
我试过了,但没用,但你可以看到我在做什么
def priceusd(assetname): '{}btc'.format(assetname)['close'][-1]*btcusdtclose[-1].
非常感谢。
【问题讨论】:
-
用字符串作为键和数据帧作为值的字典,然后在函数中使用传递的字符串查找数据帧。
标签: python pandas cryptocurrency