拿到公司一个数据文件,分隔符是|!
自然用下面的代码进行读取
df = pd.read_csv(path,sep='|!');
然后非常慢,有一个warning:
ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators (separators > 1 char and different from '\s+' are interpreted as regex);
大意是说长度为1以上的分隔符会被当做正则表达式来处理,无法进行C优化。
这会导致读大文件非常慢,不要去别的文本编辑器里修改分隔符,有可能导致更多问题。解决方法如下:
df = pd.read_csv(path,sep='|',dtype=str);
df[1] = df[1].str.strip('!')
......
这样就解决问题了,速度也不慢~