Search code examples
pythonpython-3.xpandasvalueerror

"ValueError" occurs when creating DataFrame of dictionary


I try to create a pandas DataFrame of a dictionary of pandas Series, and for some cases the following error is raised:

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)

I found solutions where the same error occurred, but they are all using lists as input for their dataframe.

The error rises in the following line of my code.

resultRFF = pd.DataFrame({'breakdowns': breakdown['type'], 'ranks': ranksRFF})

ranksRFF and breakdown['type'] are both pandas Series, with the same length and indices.

The error not raised in all cases, and is apparently triggered in the case where the length of these Series is 0.


Solution

  • Apparently pandas cannot handle empty series. The solution for me is to just catch those exeptions.