我尝试为pandas系列的dictionary创建一个pandas数据帧,在某些情况下会出现以下错误:
ValueError: Shape of passed values is (1, 2), indices imply (0, 2)"Shape of passed values is {0}, indices imply {1}".format(passed, implied)ValueError: Shape of passed values is (1, 2), indices imply (0, 2)
我找到了出现相同错误的解决方案,但它们都使用列表作为数据帧的输入。你知道吗
错误出现在我的代码的下面一行。你知道吗
resultRFF = pd.DataFrame({'breakdowns': breakdown['type'], 'ranks': ranksRFF})
ranksRFF
和breakdown['type']
都是熊猫系列,具有相同的长度和索引。你知道吗
并非所有情况下都会出现此错误,而且在这些序列的长度为0的情况下显然会触发此错误。你知道吗
显然熊猫不能处理空序列。我的解决办法就是抓住那些例外。你知道吗
试试这个:
请试试这个
pd.DataFrame([{'breakdowns': breakdown['type'], 'ranks': ranksRFF}])
,我的意思是把列表传递到数据帧中相关问题 更多 >
编程相关推荐