在用pd.read_csv
读数据时,将要转换数据类型的列名和类型名构成字典,传给dtype
import numpy as np
import pandas as pd
path = 'house_data.csv'
col = ['CRIM', 'ZN', 'INDUS', 'CHAS', 'NOX', 'RM', 'AGE', 'DIS',
'RAD', 'TAX', 'PTRATIO', 'B', 'LSTAT', 'MEDV']
dict_dtype = { }
for i in col:
dict_dtype[i] = np.float64
# print(dict_dtype)
data = pd.read_csv(path, header=None, names=col, sep=',', dtype=dict_dtype)