【问题标题】:Return a dict from map function从 map 函数返回一个字典
【发布时间】:2021-09-08 05:30:45
【问题描述】:

这里是新手,你好!我正在使用 map() 函数通过具有多处理功能的 OHLCV 下载函数来迭代 Tickers(字符串)列表。结果,我收到了一个数据框列表。

All_coins_history = Shark_pool.map(refractor_get_history, Tickers)

由于我的历史数据框只有Dataframe[["Open", "High", "Low", "Close", "Volume"]] 格式,我无法知道 All_coins_history 列表中的哪些数据适用于哪个 Ticker。例如,创建字典而不是列表的简洁方法是什么,其中每个数据帧都将其 Ticker 作为键?

【问题讨论】:

  • 请添加一些示例输入和输出数据,以及更多代码以澄清您的问题(例如,Shark_poolrefactor_get_historyTickers 是什么?)。理想情况下,您的问题应包含minimal reproducible example
  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: python pandas dataframe dictionary


【解决方案1】:

使用zip() 将股票代码与映射结果配对,然后调用dict() 创建字典。

all_coins_history = dict(zip(Tickers, Shark_pool.map(refractor_get_history, Tickers)))

【讨论】:

    猜你喜欢
    • 2017-11-23
    • 2018-05-15
    • 2019-11-22
    • 2011-05-01
    • 1970-01-01
    • 2019-03-23
    • 2015-06-05
    • 2020-04-19
    • 1970-01-01
    相关资源
    最近更新 更多