我有以下内容:
a = {
"url": "http://www.example.com",
"list": ["abc", "def", "ghi"]
}
DataFrame(a)
*****Output*****
url list
0 http://www.example.com abc
1 http://www.example.com def
2 http://www.example.com ghi
我想要实现的是这样的:
url list
0 http://www.example.com [abc, def, ghi]
如何获得预期的输出?我尝试将 a["list"]
转换为 DataFrame
、DataFrame(a, index=[0])
以及来自谷歌搜索的其他想法,但没有任何效果。
最佳答案
您可以将列表放入列表中。
a = {
"url": "http://www.example.com",
"list": [["abc", "def", "ghi"]]
}
关于python - 转换为 DataFrame 时,如何防止字典内的列表拆分成行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56229473/