pandas 读取excel的指定列

不管对于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]

 

posted @ 2018-03-07 17:44  chen狗蛋儿  阅读(59863)  评论(0编辑  收藏  举报