Cofeinnie Bonda Cofeinnie Bonda - 6 months ago 20
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?



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.