Python Pandas: ValueError: DataFrame Constructor Not Properly Called!

347    Asked by Anil Mer in Python , Asked on Nov 17, 2022

I am trying to create a Python Pandas Dataframe using this code:

df1=pd.DataFrame('Email')
But I am getting this error:

ValueError: DataFrame constructor not properly called!

Answered by Amit Sinha

Just ran into the same error - dataframe constructor not properly called. My code worked fine on my computer which was like this:

test_dict = {'x': '123', 'y': '456', 'z': '456'}
df=pd.DataFrame(test_dict.items(),columns=['col1','col2'])
However, it did not work on another platform. It gave me the same error as mentioned in the original question. I tried below code by simply adding the list() around the dictionary items, and it worked smoothly after:
df=pd.DataFrame(list(test_dict.items()),columns=['col1','col2'])


Your Answer

Interviews

Parent Categories