filename = "14.5GHZ.csv"
parts = filename.rsplit(".", 1)
print(parts)使用Python的rsplit()方法,并设置maxsplit参数为1,这样它只会从右侧拆分一次。这样可以确保小数点不被作为拆分点。
輸出結果:

使用正則表示法
import re
filename = "14.5GHZ.csv"
parts = re.split(r"\.(?!\d)", filename)
print(parts)輸出結果:

使用正则表达式模式\.(?!\d)进行拆分,该模式匹配一个点(.)后面不跟随数字的情况。这样,文件名 “14.5GHZ.csv” 就被拆分为两部分:[‘14.5GHZ’, ‘csv’]。正则表达式模式中的(?!\d)是一个负向前瞻断言,表示后面不应该跟随数字。
使用正则表达式进行拆分可以提供更灵活的拆分规则,以适应各种情况。但需要注意正则表达式的编写和匹配规则,确保满足您的拆分需求。
使用os模組:
os.path.splitext(filename)輸出:

推薦hahow線上學習python: https://igrape.net/30afN
![Python: 如何使用pandas.to_numeric ( df[‘numbers’], errors=’coerce’) 將非數值型資料轉為NaN? df[‘numbers’].describe() 簡述統計資料 Python: 如何使用pandas.to_numeric ( df[‘numbers’], errors=’coerce’) 將非數值型資料轉為NaN? df[‘numbers’].describe() 簡述統計資料](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2024/05/20240501052102_0.png?quality=90&zoom=2&ssl=1&resize=350%2C233)



![Python爬蟲:BeautifulSoup的 .find_all() 與 .find() 與 .select(‘標籤名[屬性名1=”屬性值1″][屬性名2=”屬性值2″]’) ; from bs4 import BeautifulSoup ; Live Server(可以預覽HTML的VS Code套件) Python爬蟲:BeautifulSoup的 .find_all() 與 .find() 與 .select(‘標籤名[屬性名1=”屬性值1″][屬性名2=”屬性值2″]’) ; from bs4 import BeautifulSoup ; Live Server(可以預覽HTML的VS Code套件)](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2025/03/20250330190318_0_925655.jpg?quality=90&zoom=2&ssl=1&resize=350%2C233)





近期留言