python -- 解决If using all scalar values, you must pass an index问题

Posted nxf_rabbit75

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python -- 解决If using all scalar values, you must pass an index问题相关的知识,希望对你有一定的参考价值。

【问题描述】

在将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 -- 解决If using all scalar values, you must pass an index问题的主要内容,如果未能解决你的问题,请参考以下文章

尝试合并多个数据帧时,如何解决“ValueError: If using all scalar values, you must pass an index”

pandas.apply expand column ValueError: If using all scalar values, you must pass a index

python if all

解决了| Python:If/elif/else 语句未按预期工作?

WARNING: The notebook server is listening on all IP addresses and not using encryption--Jupyter解决方案(

WARNING: The notebook server is listening on all IP addresses and not using encryption--Jupyter解决方案(