首页 > 其他 > 详细

pandas 读取excel的指定列

时间:2018-03-07 17:54:26      阅读:1220      评论:0      收藏:0      [点我收藏+]

不管对于read_csv还是read_excel,现在都有:

usecols : int or list, default None

  • If None then parse all columns,
  • If int then indicates last column to be parsed
  • If list of ints then indicates list of column numbers to be parsed
  • If string then indicates comma separated list of Excel column letters and column ranges (e.g. “A:E” or “A,C,E:F”). Ranges are inclusive of both sides.

而之前版本的:

parse_cols : int or list, default None

Deprecated since version 0.21.0: Pass in usecols instead.

可以看到在0.21.0版本后就已经完全被上面的那个给替代了。

这也算解决了我一个头疼的问题,总是把两个read的内容记混了。

所以对于最新版的pandas,只需要:

df = pd.read_excel("data.xlsx", usecols=[0, 5]) # 指定读取第1列和第6列
# 当然也可以用"A,F"代替[0,5]

 

pandas 读取excel的指定列

原文:https://www.cnblogs.com/cymwill/p/8523877.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!