import pandas as pd
dfRaw = pd.read_csv(‘test.txt’)
print(“dfRaw:\n”,dfRaw)
df = pd.read_csv(‘test.txt’, skiprows=[-1,-2])
#skiprows使用負數索引無效
print(“\ndf(使用skiprows):\n”,df)
df_footer = pd.read_csv(‘test.txt’,
skiprows=1, skipfooter=1,
engine=’python’)
print(“\ndf_footer:\n”,df_footer)
“””
#skiprows=1 略過首1 row
#skipfooter=1 略過末1 row
#若參數中沒寫 engine=’python’
#仍可以使用,只是會跳出警告訊息:
#ParserWarning: Falling back to the ‘python’ engine
#because the ‘c’ engine does not support skipfooter;
#you can avoid this warning by specifying engine=’python’.
# df_footer = pd.read_csv(‘test.txt’,
engine='python'是因为默认情况下
Pandas使用的是C引擎解析CSV文件,
而skipfooter参数需要使用Python引擎才能生效。
“Footer” 可以翻譯為 “頁腳”,通常指網頁底部的區域,
包含版權聲明、聯絡資訊、隱私政策等相關資訊。”””

輸出結果:

0-indexed 是指从0开始编号,而不是从1开始编号。在 Python 中,许多数据类型都是从0开始编号的,比如列表、字符串、元组等等。因此,当我们使用pandas中的skiprows参数时,需要将要跳过的行数按照行号从0开始进行指定。
推薦hahow線上學習python: https://igrape.net/30afN




![Python 進階技巧:海象運算子 (Walrus Operator) 實戰教學 [w_clean for w in words if (w_clean:=w.lower().strip()) and w_clean not in STOPWORDS] Python 進階技巧:海象運算子 (Walrus Operator) 實戰教學 [w_clean for w in words if (w_clean:=w.lower().strip()) and w_clean not in STOPWORDS]](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2026/02/20260210083748_0_a7d9bf.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


![Python常用的模組內建常數; __name__ ; __file__ ; __doc__ ; __all__ ;__dict__; vars()->Dict[str,str] ; dir()->List[str] Python常用的模組內建常數; __name__ ; __file__ ; __doc__ ; __all__ ;__dict__; vars()->Dict[str,str] ; dir()->List[str]](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2022/11/20221112184006_50.png?quality=90&zoom=2&ssl=1&resize=350%2C233)



近期留言