python3数据分析—运用numpy读取csv大数据文件,TypeError: datatype ‘string‘ not understood解决办法
2021/12/22 9:19:35
本文主要是介绍python3数据分析—运用numpy读取csv大数据文件,TypeError: datatype ‘string‘ not understood解决办法,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
文章目录
- 开发工具
- 问题代码
- 问题分析
- 解决代码
- 总结
开发工具
python版本:Python 3.6.1
python开发工具:JetBrains PyCharm 2018.3.6 x64
第三方库numpy安装→pip install numpy -i http://mirrors.aliyun.com/pypi/simple/
csv测试数据.csv→文件下载地址
https://url71.ctfile.com/f/13238771-529977809-0e9b4d
(访问密码:8835)
问题代码
import numpy filename = 'csv测试数据.csv' data = numpy.loadtxt(filename, dtype='string', delimiter=',', encoding='utf-8') print(data)
问题分析
在文件dtype指定类型为string不是指定的类型,在python3中表示字符串用str
解决代码
import numpy filename = 'csv测试数据.csv' data = numpy.loadtxt(filename, dtype='str', delimiter=',', encoding='utf-8') # 指定dtype为str print(data)
总结
运用numpy读取文件时,注意python版本问题,python3中dtype需要用str来代替string
这篇关于python3数据分析—运用numpy读取csv大数据文件,TypeError: datatype ‘string‘ not understood解决办法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python