Pandas

NumPy

https://blog.csdn.net/weixin_43593330/article/details/89882187

实例:numpy读取CSV文件

  1. import paddle
  2. import numpy as np
  3. import json
  4. import matplotlib.pyplot as plt
  5. import os
  6. # import csv
  1. # 读入训练数据
  2. train_data_path = 'work/kidney_data2.csv'
  3. test_data_path = 'work/kidney_data_test.csv'
  1. # np.loadtxt(data_path,dtype="",delimiter=None,skiprows=0,usecols=None,unpack=False)
  2. # train_data_path,文件路径字符串
  3. # dtype=np.float32,数据类型设置为float32
  4. # delimiter=",",csv文件数据分隔符为",",英文逗号
  5. # skiprows=2,跳过前两行
  6. # usecols=(1,2,3,4,5,6,7,8,9)),选取特定列
  7. train_dataset = np.loadtxt(train_data_path,
  8. dtype=np.float32,
  9. delimiter=",",
  10. skiprows=2,
  11. usecols=(1,2,3,4,5,6,7,8,9))
  12. # 显示一下
  13. train_dataset

array([[ 0. , 9.8 , 4.1 , …, 82. , 35. , 0.57],
[ 0. , 10.3 , 5.3 , …, 142. , 48. , 0.66],
[ 0. , 11.8 , 5.1 , …, 64. , 31.2 , 0.5 ],
…,
[ 1. , 9.8 , 4.2 , …, 50.5 , 17.1 , 0.66],
[ 1. , 11.2 , 5.2 , …, 58.5 , 15.2 , 0.74],
[ 1. , 11.6 , 5.7 , …, 128. , 36.5 , 0.71]],
dtype=float32)

  1. # 同样的方法,读取测试集文件
  2. test_dataset = np.loadtxt(test_data_path,
  3. dtype=np.float32,
  4. delimiter=",",
  5. skiprows=2,
  6. usecols=(1,2,3,4,5,6,7,8,9))
  7. test_dataset

matplotlib数据可视化