python读取excel数据并转化为DataFrame类型

本文介绍使用Pandas库中的read_excel方法从本地Excel文件(DB1.xlsx)读取指定列和行的数据,直接返回DataFrame类型,无需额外转换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 本地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)
"""
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值