【问题标题】:Dictionary into a dataframe字典到数据框
【发布时间】:2023-04-03 21:42:01
【问题描述】:

我一直在通过 pycoingecko 从 coingecko API 中提取信息

ren_daily_price=cg.get_coin_market_chart_range_by_id(id='republic-protocol',vs_currency='usd',from_timestamp=1585267200,to_timestamp=1616457600)

它给了我一个对象类型的字典

type(ren_daily_price)

字典

我正在使用此命令转换为数据框,我得到以下信息:

df=DataFrame.from_dict(ren_daily_price)
df

results

您可以看到 unix 编号代表每一行的相同日期。 如何提取日期作为索引,然后我有价格、市场上限和交易量列?

Date Prices market_caps Volume
1585267200000 0.0456998 39721342.05347 2548106.9

【问题讨论】:

  • 列的 dtype 是什么?

标签: python pandas list dataframe dictionary


【解决方案1】:

您可以尝试这样从所有单元格的列表中获取第二项:

df = df.applymap(lambda x: x[1])

【讨论】:

  • 要解决日期索引问题,请先添加此行:df.index = df.prices.map(lambda x: x[0])
猜你喜欢
  • 2017-10-15
  • 2022-08-21
  • 2021-07-17
  • 2020-12-28
  • 2013-09-12
  • 2020-05-15
  • 2016-10-17
  • 2017-08-02
相关资源
最近更新 更多