2017-08-16 30 views
1

我有一個excel文件的第一行15行作爲「標題數據」。 和之後235行,「頁腳數據」。 我需要在這些頁眉和頁腳數據之間讀取數據如何跳過熊貓數據框中的頁眉和頁腳數據?

是否有任何方法通過使用熊貓選擇特定範圍的行將數據讀入DataFrame?

+1

https://pandas.pydata.org/pandas-docs/stable/generated/pandas.ExcelFile.parse.html – MrE

+1

刪除Excel的標籤。這個問題不是關於使用Excel。 – teylyn

+0

@mob您用Excel標籤標記了問題。我刪除它。 – teylyn

回答

1

演示:

xl = pd.ExcelFile(filepath) 

# parsing first (index: 0) sheet 
total_rows = xl.book.sheet_by_index(0).nrows 

skiprows = 15 
nrows = 235 - 15 

# calc number of footer rows 
# (-1) - for the header row 
skip_footer = total_rows - nrows - skiprows - 1 

df = xl.parse(0, skiprows=skiprows, skip_footer=skip_footer) 
+0

謝謝!會嘗試這個。 – mob

+0

@mob,它工作嗎? – MaxU

+0

種,但我需要刪除一些列,但它顯示錯誤:ExcelFile不支持刪除列 – mob

-1

你有興趣的數據,從行15划船。

你可以試試這個:

import pandas as pd 

df = pd.read_excel(somefile.xls) 

df = df[15:235]