You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何不借助Pandas将字典列表转换为Polars DataFrame

直接将字典列表转换为Polars DataFrame的方案

Polars原生支持直接从字典列表创建DataFrame,完全不需要依赖Pandas,直接使用pl.DataFrame()构造器即可:

import polars as pl

# 你的字典列表数据
data = [{"id": 1, "name": "Joe", "lastname": "Bloggs"}, {"id": 2, "name": "Bob", "lastname": "Wilson"}]

# 直接转换为Polars DataFrame
df = pl.DataFrame(data)

# 查看结果
print(df)

执行后输出结果:

shape: (2, 3)
┌─────┬──────┬──────────┐
│ id  ┆ name ┆ lastname │
│ --- ┆ ---  ┆ ---      │
│ i64 ┆ str  ┆ str      │
╞═════╪══════╪══════════╡
│ 1   ┆ Joe  ┆ Bloggs   │
│ 2   ┆ Bob  ┆ Wilson   │
└─────┴──────┴──────────┘

Polars的DataFrame构造器会自动识别每个字典的键作为列名,字典中的值对应每行的列数据,同时会自动推断列的数据类型。

内容的提问来源于stack exchange,提问作者Frank Jimenez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 14:21:00