I want to read a CSV file and save it as data frame in pandas.
But I have a problem because I have rows like this:
BG,6141.6,6141.6,,3.0,,,ic
As you see there are three separators: ',,,' , ',,' and ,
How can I load it correctly into pandas?
Use regex separator [,]+ - one or more ,:
import pandas as pd
from pandas.compat import StringIO
temp=u"""iBG,6141.6,6141.6,,3.0,,,ic"""
#after testing replace 'StringIO(temp)' to 'filename.csv'
df = pd.read_csv(StringIO(temp), sep="[,]+", header=None, engine='python')
print (df)
0 1 2 3 4
0 iBG 6141.6 6141.6 3.0 ic
csv? Are there column names?