不管對於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]