#### numpy数据读取与写出;
测试数据:https://archive.ics.uci.edu/ml/machine-learning-databases/iris/
import numpy as np
import os
os.chdir("D://python_script//")
a = np.loadtxt("iris.data", dtype = float64, delimiter=',', usecols = [0, 1, 2, 3])
print(a)
b = np.loadtxt("iris.data", dtype = "S", delimiter=',', usecols = [4])
print(b)
for x in range(len(b)):
print(a[x], "is ", b[0])
#指定数据类型,导入数据
t = np.dtype([('sepal_length', 'f'),('sepal_width','f'),('petal_length','f'),('petal_width','f'),('class','S20')])
a = np.loadtxt("iris.data", dtype = t, delimiter=',')
print(a)
r = np.savetxt("iris.csv", a, fmt='%3.1f:%3.1f:%3.1f:%3.1f:%s')
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!