如何使用熊猫只读取excel标头?

 收藏

我知道用熊猫读过Excel表:

import pandas as pd

table = pd.read_excel(io)

加载数据后,如果要获取表头:

table.columns

This method is feasible, but sometimes I just want to get the header of the excel table directly, especially when the excel table has a large body size, it will be very time-consuming to load the data table into the memory & it is also unnecessary, sometimes it even overflows directly and gets stuck. Looking at the official documents, it seems that I can use the nrows parameter to specify that only specific lines of Excel can be read, This means that I can use it to read only the first row header:

header = pd.read_excel(io, nrows = 0)

但是,我发现熊猫也无法阻止读取整个excel数据,并且仍然会消耗大量时间和内存。您在处理此问题方面有良好的经验吗?

回复