Python Pandas ValueError DataFrame constructor not properly called

0 votes

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


But I am getting this error:

ValueError: DataFrame constructor not properly called!
Mar 28, 2019 in Python by Shri

3 answers to this question.

+1 vote

The syntax is not right. The right syntax is as follows:

answered Mar 28, 2019 by Ritu
0 votes

You are providing a string representation of a dict to the DataFrame constructor, and not a dict itself. So this is the reason you get that error.

So if you want to use your code, you could do:

df = DataFrame(eval(data))

But better would be to not create the string in the first place, but directly putting it in a dict. Something roughly like:

data = []
for row in result_set:
    data.append({'value': row["tag_expression"], 'key': row["tag_name"]})

But probably even this is not needed, as depending on what is exactly in your result_set you could probably:

  • provide this directly to a DataFrame: DataFrame(result_set)
  • or use the pandas read_sql_query function to do this for you.

Hope it works!!

If you are a beginner and need to know more about Python, It's recommended to go for Python Certification course today.


answered Dec 11, 2020 by Gitika
• 65,950 points
0 votes

It seems you need list:

df2 = pd.DataFrame(['Test'])
print (df2)
0  Test


It seems you need:

def multiple_dfs(file_name, sheet, *args):
    Put multiple dataframes into one xlsx sheet

    writer = pd.ExcelWriter(file_name)

    df = pd.DataFrame({'user': ['Bob', 'Jane', 'Alice'], 
               'income': [40000, 50000, 42000]})
    df2 = pd.DataFrame({'amount': [100, 500, 1000], 
               'income': [40000, 50000, 42000]})
    df3 = pd.DataFrame(['Title'])

    df.to_excel(writer, sheet, startrow=row, index=False)
    row += len(df) + 1
    df2.to_excel(writer, sheet, startrow=row, index=False)
    df3.to_excel(writer, sheet, startrow=0, startcol=0, header=None, \

answered Dec 11, 2020 by Rajiv
• 8,890 points

Related Questions In Python

–1 vote
1 answer
0 votes
3 answers
0 votes
1 answer

How to create Pandas dataframe from Python list?

You can do it like this: import ...READ MORE

answered Apr 6, 2019 in Python by Likhita
0 votes
1 answer

Pandas dataframe with multiple lists in Python

You can do it like this import pandas ...READ MORE

answered Apr 6, 2019 in Python by Esha
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,402 views
0 votes
0 answers
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
0 votes
1 answer

How to convert a Pandas GroupBy object to DataFrame in Python

g1 here is a DataFrame. It has a hierarchical index, ...READ MORE

answered Nov 12, 2018 in Python by Nymeria
• 3,520 points
0 votes
2 answers

Python Pandas error: AttributeError: 'DataFrame' object has no attribute 'rows'

Try this: data=pd.read_csv('/your file name', delim_whitespace=Tru ...READ MORE

answered Dec 10, 2020 in Python by anonymous
• 82,820 points