python - Too many values to unpack when creating a data frame from two lists -
i have list c
, p
, both have 35300 elements. try create pandas data frame there´s error message when run code. how can fix this?
import pandas pd e=pd.dataframe.from_items(['company',c],['id',p]) --------------------------------------------------------------------------- valueerror traceback (most recent call last) <ipython-input-284-89427a7d8af3> in <module>() 1 import pandas pd 2 ----> 3 e=pd.dataframe.from_items(['company',c],['id',p]) c:\users\toshiba\anaconda\lib\site-packages\pandas\core\frame.pyc in from_items(cls, items, columns, orient) 1195 frame : dataframe 1196 """ -> 1197 keys, values = zip(*items) 1198 1199 if orient == 'columns': valueerror: many values unpack
since c
, p
lists, sounds want define dataframe 2 columns, company
, id
:
e = pd.dataframe({'company':c, 'id':p})
as behzad.nouri's suggests,
e = pd.dataframe.from_items([('company',c), ('id',p)])
would work, , unlike first suggestion, fix order of columns.
Comments
Post a Comment