Skip to content
Advertisement

ValueError: Shape of passed values is (4, 4), indices imply (1, 4)

Can someone explain to me what is the cause of this error?

JavaScript

Advertisement

Answer

The issue is the index=['col1'] argument. The data you’re passing to pd.DataFrame() is a list of 4 lists, where each list has 4 items, so there will be 4 rows and 4 columns.

But, you’re setting the index (row labels) to be only 1 item, when there are going to be 4 items. You need to either reduce the data to 1 row, or add 3 more items to your index=['col1'] list:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement