Reputation: 105
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.
Upvotes: 0
Views: 171
Reputation: 105
Apparently pandas cannot handle empty series. The solution for me is to just catch those exeptions.
Upvotes: 0
Reputation: 269
Try this:
resultRFF = pd.DataFrame({'breakdowns': breakdown['type'].values, 'ranks': ranksRFF.values})
Upvotes: 1
Reputation: 3
Please try this pd.DataFrame([{'breakdowns': breakdown['type'], 'ranks': ranksRFF}])
, I mean pass the list into DataFrame
Upvotes: 0