"C:/Users/DELL/Desktop/python_flask-dc/python_flask/bpnn_tf.py", line 47, in <module> dataset = pd.read_csv('2019.csv', delimiter=",") File "E:\python-3.7.0\lib\site-packages\pandas\io\parsers.py", line 688, in read_csv return _read(filepath_or_buffer, kwds) File "E:\python-3.7.0\lib\site-packages\pandas\io\parsers.py", line 460, in _read data = parser.read(nrows) File "E:\python-3.7.0\lib\site-packages\pandas\io\parsers.py", line 1198, in read ret = self._engine.read(nrows) File "E:\python-3.7.0\lib\site-packages\pandas\io\parsers.py", line 2157, in read data = self._reader.read(nrows) File "pandas\_libs\parsers.pyx", line 847, in pandas._libs.parsers.TextReader.read File "pandas\_libs\parsers.pyx", line 862, in pandas._libs.parsers.TextReader._read_low_memory File "pandas\_libs\parsers.pyx", line 918, in pandas._libs.parsers.TextReader._read_rows File "pandas\_libs\parsers.pyx", line 905, in pandas._libs.parsers.TextReader._tokenize_rows File "pandas\_libs\parsers.pyx", line 2042, in pandas._libs.parsers.raise_parser_error pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 9, saw 3
时间: 2023-08-06 13:05:54 浏览: 61
这个报错与第一个问题很相似,也是在读取 '2019.csv' 文件时出现了解析错误。具体是在第9行有3个字段,而程序期望只有1个字段。同样的,你可以检查文件的格式是否正确,尝试重新整理或清洗文件中的数据,以确保数据格式的一致性。此外,你可以尝试指定文件的编码方式,例如使用 `encoding='utf-8'` 参数来读取文件。
相关问题
Traceback (most recent call last): File "C:/Users/DELL/Desktop/python_flask-dc/python_flask/app.py", line 43, in <module> from python_flask.bpnn_tf import predicttem File "C:\Users\DELL\Desktop\python_flask-dc\python_flask\bpnn_tf.py", line 132, in <module> a = '{:.2f}'.format(a) # 将结果输出为字符串格式 TypeError: unsupported format string passed to numpy.ndarray.__format__
这个错误提示是因为在使用格式化字符串时传入了不支持的格式化字符,而这个格式化字符是传给了一个 numpy 的数组。你可以尝试将这个数组转换为 Python 的列表或元组,然后再进行格式化输出。在 Python 中,可以使用 `tolist()` 方法将 numpy 数组转换为 Python 列表。修改代码如下:
```
a = model.predict(test_data).flatten().tolist()
a = '{:.2f}'.format(a[0]) # 将结果输出为字符串格式
```
这样就可以避免这个错误了。
Traceback (most recent call last): File "C:/Users/DELL/Desktop/python_flask-dc/python_flask/bpnn_tf.py", line 131, in <module> a = round(a[0][0], 2) # 对浮点数进行四舍五入 TypeError: type numpy.ndarray doesn't define __round__ method
这个错误是因为 numpy.ndarray 类型没有定义 __round__ 方法,不能进行四舍五入操作。你可以尝试使用 numpy.around 函数来实现类似的功能,例如:
```
a = np.around(a[0][0], decimals=2)
```
这会将 a[0][0] 的值四舍五入到小数点后两位,并返回一个浮点数。如果你需要将其转换为字符串,可以使用 str 函数,例如:
```
result = str(a)
```
这会将浮点数 a 转换为字符串类型的 result。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)