在pandas表开始之前的数据
我正在使用pandasparsing一个20k行数据表的Excel文件。 到目前为止这么好,但是在表的起始位置还有一小部分元数据,我也想使用它(生成表的date)。
目前如果我不跳过任何行:
raw = pd.read_excel(datafile, sheetname=0, parse_cols="B, D:I")
前几行只是nans:
>>> raw.values[0] array([nan, nan, nan, nan, nan, nan, nan], dtype=object)
我可以用像xlrd这样更基本的文件来打开这个文件来获取这些数据,但这需要将整个文件加载到内存中两次,而我却不想这样做。
pandas可以在不重新导入文件的情况下获取表格上方的数据吗?
考虑以下方法:
xl = pd.ExcelFile(filepath) # you may want to set a correct row and column meta_data = xl.book.sheet_by_index(0).cell_value(0,0) skiprows = 5 # set it accordnigly... df = xl.parse(0, skiprows=skiprows, parse_cols="B, D:I") \ .dropna(axis=1, how='all')