python - Read CSV file using Pandas: complex separator -
i have csv file want read using python panda. header , lines looks following:
^b^c^d^e ^f ^g ^h^i^j^k^l^m^n
clearly seen that, separator ^, there odd spaces. how can read file perfectly?
i using following command read csv file:
df = pd.read_csv('input.csv', sep='^')
use regex \s*\^
means 0 or more whitespace , ^, have specify python engine here avoid warning regex support:
in [152]: t="""a ^b^c^d^e ^f ^g ^h^i^j^k^l^m^n""" df= pd.read_csv(io.stringio(t), sep='\s*\^', engine='python') df.columns out[152]: index(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n'], dtype='object')
Comments
Post a Comment