【问题描述】
在将dict转为DataFrame时会报错:If using all scalar values, you must pass an index
例如:
summary = pd.DataFrame({key:value for key,value in test.items()if key in index}) #查看汇总表情况
【解决办法】
添加参数:index = [0]
summary = pd.DataFrame({key:value for key,value in test.items()if key in index},index = [0]) #查看汇总表情况没报错!问题解决!
(仅供个人学习,不负责任~~~~~~~~~~~~)

本文介绍了一种在Python中将字典(dict)转换为Pandas DataFrame时遇到的常见错误:“If using all scalar values, you must pass an index”。文章提供了一个简单有效的解决方案,即通过为DataFrame构造函数添加index参数来避免这一错误。

1万+

被折叠的 条评论
为什么被折叠?



