python - import csv with different number of columns per row using Pandas -


what best approach importing csv has different number of columns each row using pandas or csv module pandas dataframe.

"h","bbb","d","ajxxx dxxxs" "r","1","qh","dtr"," "," ","spxxt rixxls, raxxxd","1" 

using code:

import pandas pd data = pd.read_csv("smallsample.txt",header = none) 

the following error generated

error tokenizing data. c error: expected 4 fields in line 2, saw 8 

supplying list of columns names in read_csv() should trick.

ex: names=['a', 'b', 'c', 'd', 'e']

https://github.com/pydata/pandas/issues/2981

edit: if don't want supply column names nicholas suggested


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -