我有一个这样的数据结构:data = [{ "name": "leopard", "character": "mean", "skills": ["sprinting", "hiding"], "pattern": "striped", }, { "name": "antilope", "character": "good", "skills": ["running"], }, . . .]字典中的每个键都有整数、字符串或 字符串列表类型的值(并非所有键都在所有字典中),每个字典代表表中的一行;所有行都作为字典列表给出。如何轻松地将其导入 Pandas?我试过df = pd.DataFrame.from_records(data)但在这里我得到一个“ValueError: arrays must all be same length”错误。
1 回答
湖上湖
TA贡献2003条经验 获得超2个赞
的DataFrame构造函数采用基于行的阵列(amoungst其它结构)作为数据输入。因此,以下工作:
data = [{
"name": "leopard",
"character": "mean",
"skills": ["sprinting", "hiding"],
"pattern": "striped",
},
{
"name": "antilope",
"character": "good",
"skills": ["running"],
}]
df = pd.DataFrame(data)
print(df)
输出:
character name pattern skills
0 mean leopard striped [sprinting, hiding]
1 good antilope NaN [running]
添加回答
举报
0/150
提交
取消