- 本地excel文件
- pandas模型中的read_excel方法
'''加载数据集'''
#pandas模型中的read_excel方法读取excel的xlsx数据
import pandas as pd
xlsx_file = "DB1.xlsx"
"""
# read_excel方法读取文件
xlsx_feature = pd.read_excel(xlsx_file, usecols=[1, 2, 3, 4, 5, 6, 7]) #usecols属性读取excel文件中的指定列,列号从0起始;skiprows属性跳过excel文件中指定行,行号从0起始
xlsx_target = pd.read_excel(xlsx_file, usecols=[8])
#通过pd.DataFrame将excel文件转化为DataFrame类型,多此一举
feature = pd.DataFrame(xlsx_feature)
target = pd.DataFrame(xlsx_target)
# print(type(feature))
# print(feature)
# print(type(target))
# print(target)
"""
# read_excel方法返回类型为DataFrame,不需要再次转换
feature = pd.read_excel(xlsx_file, usecols=[1, 2, 3, 4, 5, 6, 7])
target = pd.read_excel(xlsx_file, usecols=[8])
# print(type(feature))
# print(type(target))
# print(feature)
# print(target)
ps:
此处用到的excel文件放进了当前工程目录中,所以xlsx_file = "DB1.xlsx"
只写文件名即可成功读取。不放进来则需要写完整路径 eg:xlsx_file="E:\mydata\DB1.xlsx"