gpt4 book ai didi

python - 使用 read_csv 时,我收到 sre_constants.error : nothing to repeat at position 0

转载 作者:行者123 更新时间:2023-12-01 09:17:48 26 4
gpt4 key购买 nike

我正在使用 Pandas 。我已经下载了成人数据集并将其转换为 csv 文件,现在我尝试使用 read_csv 函数读取 csv 文件,但出现以下错误:

 sre_constants.error: nothing to repeat at position 0

这是我的代码中发生错误的行-

    adult_df = pd.read_csv('E:/iris dataset/adultdata.csv',header=None, 
delimiter='*,*', engine='python')
print(adult_df.isnull().sum())

这是回溯-

        C:\Users\Sharanya\AppData\Local\Programs\Python\Python36-32\lib\site-packages\sklearn\cross_validation.py:41: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
"This module will be removed in 0.20.", DeprecationWarning)
Traceback (most recent call last):
File "E:\iris dataset\naive_bayes_adult_dataset.py", line 9, in <module>
adult_df = pd.read_csv('E:/iris dataset/adultdata.csv',header=None, delimiter='*,*', engine='python')
File "C:\Users\Sharanya\AppData\Roaming\Python\Python36\site-packages\pandas\io\parsers.py", line 678, in parser_f
return _read(filepath_or_buffer, kwds)
File "C:\Users\Sharanya\AppData\Roaming\Python\Python36\site-packages\pandas\io\parsers.py", line 440, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "C:\Users\Sharanya\AppData\Roaming\Python\Python36\site-packages\pandas\io\parsers.py", line 787, in __init__
self._make_engine(self.engine)
File "C:\Users\Sharanya\AppData\Roaming\Python\Python36\site-packages\pandas\io\parsers.py", line 1024, in _make_engine
self._engine = klass(self.f, **self.options)
File "C:\Users\Sharanya\AppData\Roaming\Python\Python36\site-packages\pandas\io\parsers.py", line 2089, in __init__
self.columns, self.num_original_columns = self._infer_columns()
File "C:\Users\Sharanya\AppData\Roaming\Python\Python36\site-packages\pandas\io\parsers.py", line 2455, in _infer_columns
line = self._buffered_line()
File "C:\Users\Sharanya\AppData\Roaming\Python\Python36\site-packages\pandas\io\parsers.py", line 2530, in _buffered_line
return self._next_line()
File "C:\Users\Sharanya\AppData\Roaming\Python\Python36\site-packages\pandas\io\parsers.py", line 2635, in _next_line
orig_line = self._next_iter_line(row_num=self.pos + 1)
File "C:\Users\Sharanya\AppData\Roaming\Python\Python36\site-packages\pandas\io\parsers.py", line 2695, in _next_iter_line
return next(self.data)
File "C:\Users\Sharanya\AppData\Roaming\Python\Python36\site-packages\pandas\io\parsers.py", line 2229, in _read
pat = re.compile(sep)
File "C:\Users\Sharanya\AppData\Local\Programs\Python\Python36-32\lib\re.py", line 233, in compile
return _compile(pattern, flags)
File "C:\Users\Sharanya\AppData\Local\Programs\Python\Python36-32\lib\re.py", line 301, in _compile
p = sre_compile.compile(pattern, flags)
File "C:\Users\Sharanya\AppData\Local\Programs\Python\Python36-32\lib\sre_compile.py", line 562, in compile
p = sre_parse.parse(p, flags)
File "C:\Users\Sharanya\AppData\Local\Programs\Python\Python36-32\lib\sre_parse.py", line 855, in parse
p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, 0)
File "C:\Users\Sharanya\AppData\Local\Programs\Python\Python36-32\lib\sre_parse.py", line 416, in _parse_sub
not nested and not items))
File "C:\Users\Sharanya\AppData\Local\Programs\Python\Python36-32\lib\sre_parse.py", line 616, in _parse
source.tell() - here + len(this))
sre_constants.error: nothing to repeat at position 0

最佳答案

参数delimiter需要一个单个字符分隔符,或者如果它有多个字符,则将其视为正则表达式。

星号 (*) 在正则表达式中具有特殊含义 - 重复前一个字符。

在您的情况下delimiter='*,*' 第一个星号无需重复。

所以试试这个:

delimiter='\*,\*'

如果确实有 *,* 作为分隔符

关于python - 使用 read_csv 时,我收到 sre_constants.error : nothing to repeat at position 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51080171/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com