Shape of passed values is (passed), indices imply (implied)
Package:
pandas
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,
*,
Links to the raise (1)
https://github.com/pandas-dev/pandas/blob/b3e335254f46a526ee3ce9bb757eac4011d9d1fe/pandas/core/internals/construction.py#L398Ways to fix
Error code:
import pandas as pd
import numpy as np
values = np.array([[1,2,3],[4, 5, 6]]) #<---(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],[4, 5, 6],[7,8,9]]) #<--- (3,3)
columns=['a', 'b', 'c']
index=['1','2','3']
at = pd.DataFrame(values,index,columns)
print(at)
Add a possible fix
Please authorize to post fix