votes up 4

Shape of passed values is (passed), indices imply (implied)

Package:
pandas
github stars 30911
Exception Class:
ValueError

Raise code

        # Could let this raise in Block constructor, but we get a more
        #  helpful exception message this way.
        if values.shape[0] == 0:
            raise ValueError("Empty data passed with indices specified.")

        passed = values.shape
        implied = (len(index), len(columns))
        raise ValueError(f"Shape of passed values is {passed}, indices imply {implied}")


def dict_to_mgr(
    data: dict,
    index,
    columns,
    *,
😲  Walkingbet is Android app that pays you real bitcoins for a walking. Withdrawable real money bonus is available now, hurry up! 🚶

Ways to fix

votes up 2 votes down

Error code:

import pandas as pd
import numpy as np

values = np.array([[1,2,3],[456]]) #<---(2,3)
columns=['a''b''c']  #<--- lenght is 3
index=['1','2','3']   #<--- lenght is 3 

at = pd.DataFrame(values,index,columns)
print(at)

Explanation:

values shape must be suitable for the length of columns and index. Because columns and index both of them are like matrix. Here we have (2,3) shape values, and our columns and index is (3,3)

Fix code:

import pandas as pd
import numpy as np

values = np.array([[1,2,3],[456],[7,8,9]]) #<--- (3,3)
columns=['a''b''c']
index=['1','2','3']

at = pd.DataFrame(values,index,columns)
print(at)
Jul 15, 2021 anonim answer
anonim 13.0k

Add a possible fix

Please authorize to post fix