Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python错误标记化数据:如何避免不同长度引起的错误_Python_Pandas_Tokenize - Fatal编程技术网

Python错误标记化数据:如何避免不同长度引起的错误

Python错误标记化数据:如何避免不同长度引起的错误,python,pandas,tokenize,Python,Pandas,Tokenize,我正在尝试使用pandas read_csv函数读取*.dat文件 df = pd.read_csv(file, skiprows=0, header=None, sep=" ", parse_dates=[[0, 1]]) 数据如下所示: 2019-06-01 04:00:22 PW 100 2000 2000 /// // // // ////// ////// //// 2019-06-01 04:00:32 PW 100 2000 2000 /// // // // ///

我正在尝试使用pandas read_csv函数读取*.dat文件

df = pd.read_csv(file, skiprows=0, header=None, sep=" ", parse_dates=[[0, 1]])
数据如下所示:

2019-06-01 04:00:22 PW  100  2000  2000 /// // // // ////// ////// ////
2019-06-01 04:00:32 PW  100  2000  2000 /// // // // ////// ////// ////
2019-06-01 04:00:42 PW  100  2000  2000 /// // // // ////// ////// ////
2019-06-01 04:00:52 PW  100  2000  2000 /// // // // ////// ////// ////
2019-06-01 04:01:02 PW  100  2000  2000 /// // // // ////// ////// ////
2019-06-01 04:01:12 PW  100  2000  2000 /// // // // ////// ////// ////
2019-06-01 04:01:22 PW  100  2000  2000 /// // // // ////// ////// ////
2019-06-01 04:01:32 PW  100  2000  2000 /// // // // ////// ////// ////
我得到一个标记化错误:

ParserError: Error tokenizing data. C error: Expected 16 fields in line 242, saw 17
我认为这是错误的原因,因为在第242行中,第6列中的值比之前的行中的值低,例如第6列保持在2000或有4位数的值(例如1501),但在第242行中,它下降到991(三位数)

我怎样才能消除这个错误

error\u bad\u lines=False不是选项,因为我需要的正是这些值

您应该使用
sep=“+”
sep=“\s+”
而不是
sep=“
。对于后者,多个空格被分隔成多个空列,当空格数发生变化时会导致错误


或者,您可以指定
delim_whitespace=True
而不是
sep
delimiter

非常感谢!!通过添加sep=“+”它工作得非常好!我没有意识到这一点。你帮我节省了很多时间!非常感谢你
2019-06-01 04:39:32 PW  100  2000  2000 /// // // // ////// ////// ////
2019-06-01 04:39:42 PW  100  1501  2000 /// // // // ////// ////// ////
2019-06-01 04:39:52 PW  100  1501  2000 /// // // // ////// ////// ////
2019-06-01 04:40:02 PW  100  1501  2000 /// // // // ////// ////// ////
2019-06-01 04:40:12 PW  100  1187  2000 /// // // // ////// ////// ////
2019-06-01 04:40:22 PW  100  1187  2000 /// // // // ////// ////// ////
2019-06-01 04:40:32 PW  100   991  2000 /// // // // ////// ////// ////