我有一個excel文件的第一行15行作爲「標題數據」。 和之後235行,「頁腳數據」。 我需要在這些頁眉和頁腳數據之間讀取數據。如何跳過熊貓數據框中的頁眉和頁腳數據?
是否有任何方法通過使用熊貓選擇特定範圍的行將數據讀入DataFrame?
我有一個excel文件的第一行15行作爲「標題數據」。 和之後235行,「頁腳數據」。 我需要在這些頁眉和頁腳數據之間讀取數據。如何跳過熊貓數據框中的頁眉和頁腳數據?
是否有任何方法通過使用熊貓選擇特定範圍的行將數據讀入DataFrame?
演示:
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)
你有興趣的數據,從行15划船。
你可以試試這個:
import pandas as pd
df = pd.read_excel(somefile.xls)
df = df[15:235]
https://pandas.pydata.org/pandas-docs/stable/generated/pandas.ExcelFile.parse.html – MrE
刪除Excel的標籤。這個問題不是關於使用Excel。 – teylyn
@mob您用Excel標籤標記了問題。我刪除它。 – teylyn