Python Pandas: ValueError: DataFrame constructor not properly called!

Python

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!

 

2
Answers

Replies

It seems a string representation isn't satisfying enough for the DataFrame constructor. This means that you are providing a string representation of a dict to DataFrame constructor, and not a dict itself. So this is the reason you get that error. Just simply adding the list() around the dictionary items,:


df=pd.DataFrame(list(test_dict.items()),columns=['col1','col2'])


which will solve the error.


 

 

The syntax represented above is incorrect. Below is the correct syntax that has to be used.



Df1=pd.DataFrame(columns=[‘Email’])

 
 

If you want to unleash your potential in this competitive field, please visit the Python course page for more information, where you can find the Python tutorials and Python frequently asked interview questions and answers as well.

 

This topic has been locked/unapproved. No replies allowed

Login to participate in this discussion.

Leave a reply

Before proceeding, please check your email for a verification link. If you did not receive the email, click here to request another.