Cofeinnie Bonda Cofeinnie Bonda - 1 year ago 85
Python Question

pd.DataFrame() fails when combining 2 lists

I have 2 lists like below while my lists actually have 3000 elements:


When I tried to combine them to form a dataframe with 2 columns:
c=pd.DataFrame([pd.Series(a), pd.Series(b)])

It says:
TypeError: invalid type promotion

How can I solve this problem?

Answer Source


c = pd.DataFrame(data={'a':a,'b':b})

You're getting the error because you are trying to create a pandas dataframe by putting two lists together into one column, while the data types of the elements in those lists don't match. Basically, you're trying to put dates and integers into the same column.

I hope this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download