Home > Mobile >  While passing same number of column name and column data get the error
While passing same number of column name and column data get the error

Time:02-26

a=["ExpNCCIFactor","Requestid","EffDate","TransresposnseDate","QuoteEffDate","ApplicationID","PortUrl","UQuestion","DescriptionofOperations","Error"]
d = [ExpNCCIFactor,Requestid,EffDate,TransresposnseDate,QuoteEffDate,ApplicationID,PortUrl,UQuestion,DescriptionofOperations,Error]
df2 = pd.DataFrame(data = d , columns = a)

Got error

Traceback (most recent call last):
  File "C:\Users\praka\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\internals\construction.py", line 982, in _finalize_columns_and_data
    columns = _validate_or_indexify_columns(contents, columns)
  File "C:\Users\praka\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\internals\construction.py", line 1030, in _validate_or_indexify_columns
    raise AssertionError(
AssertionError: 10 columns passed, passed data had 11 columns

CodePudding user response:

You are creating a dataframe from list. In your case, data arugment should be list of list.

a=["ExpNCCIFactor","Requestid","EffDate","TransresposnseDate","QuoteEffDate","ApplicationID","PortUrl","UQuestion","DescriptionofOperations","Error"]
d = [[ExpNCCIFactor,Requestid,EffDate,TransresposnseDate,QuoteEffDate,ApplicationID,PortUrl,UQuestion,DescriptionofOperations,Error]]

CodePudding user response:

It seems like one of your columns in variable d has a different shape probably a double column on it.

Try this code to iterate over them and print their shapes:

import numpy as np
c = 0
for i in d:
    print('Shape of column {} is {}'.format(c, np.shape(i)))
    c  = 1
  • Related