【问题标题】:Python Polars: how to convert a list of dictionaries to polars dataframe without using pandasPython Polars:如何在不使用 pandas 的情况下将字典列表转换为 polars 数据框
【发布时间】:2023-01-19 03:46:50
【问题描述】:

我有一个这样的字典列表:

[{"id": 1, "name": "Joe", "lastname": "Bloggs"}, {"id": 2, "name": "Bob", "lastname": "Wilson"}]

我想将其转换为极坐标数据框。我试过通过熊猫,但如果可能的话,我想避免使用熊猫。

有什么想法吗?

【问题讨论】:

    标签: python python-polars


    【解决方案1】:

    传给pl.DataFrame

    In [2]: pl.DataFrame([{"id": 1, "name": "Joe", "lastname": "Bloggs"}, {"id": 2, "name": "Bob", "lastname": "Wilson"}])
    Out[2]:
    shape: (2, 3)
    ┌─────┬──────┬──────────┐
    │ id  ┆ name ┆ lastname │
    │ --- ┆ ---  ┆ ---      │
    │ i64 ┆ str  ┆ str      │
    ╞═════╪══════╪══════════╡
    │ 1   ┆ Joe  ┆ Bloggs   │
    │ 2   ┆ Bob  ┆ Wilson   │
    └─────┴──────┴──────────┘
    

    【讨论】:

      猜你喜欢
      • 2023-01-04
      • 2023-02-16
      • 2023-01-08
      • 2022-12-18
      • 2022-10-08
      • 2014-06-12
      • 1970-01-01
      • 2020-07-21
      • 2023-02-09
      相关资源
      最近更新 更多