在 Pandas 中,read_excel() 中使用的 read_csv() 中的“nrows"相当于什么? [英] In Pandas, whats the equivalent of 'nrows' from read_csv() to be used in read_excel()?
问题描述
只想将特定范围的数据从 excel 电子表格(.xlsm 格式,因为它具有宏)导入到 Pandas 数据框中.是这样做的:
Want to import only certain range of data from an excel spreadsheet (.xlsm format as it has macros) into a pandas dataframe. Was doing it this way:
data = pd.read_excel(filepath, header=0, skiprows=4, nrows= 20, parse_cols = "A:D")
但似乎 nrows 仅适用于 read_csv() ?read_excel() 的等价物是什么?
But it seems that nrows works only with read_csv() ? What would be the equivalent for read_excel()?
推荐答案
如果您知道 Excel 工作表中的行数,则可以使用 skip_footer 参数读取第一个 n- skip_footer 文件的行数,其中 n 是总行数.
If you know the number of rows in your Excel sheet, you can use the skip_footer parameter to read the first n - skip_footer rows of your file, where n is the total number of rows.
http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_excel.html
用法:
data = pd.read_excel(filepath, header=0, parse_cols = "A:D", skip_footer=80)
假设您的 Excel 表有 100 行,此行将解析前 20 行.
Assuming your excel sheet has 100 rows, this line would parse the first 20 rows.
这篇关于在 Pandas 中,read_excel() 中使用的 read_csv() 中的“nrows"相当于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!