[英]Extract multiple pattern from string pandas
使用從數據集中的列中提取的中間和最后一個字符串創建新列。
數據
Status ID
Ok hello_dd
Ok hello_aa_now
No standard_cc
no standard_ee_not
想要的
Status ID type
Ok hello_dd dd
Ok hello_aa_now aa
No standard_cc cc
no standard_ee_not ee
正在做
我能夠提取最后一個字符串,但是,仍在研究如何提取中間字符串。
df['type'] = df['ID'].str.strip('_').str[-1]
任何建議表示贊賞。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.