簡體   English   中英

字符串在多個定界符上分割

[英]string split on multiple delimeters

我有一個數據集,其中列信息由這樣的字符串組成:

data['info'][0] = 'Banshidhar Roadlines - Ahmedabad Address Opp. Mahadev Avenue, Nr. Sardar Patel Ring Road, Ahmedabad Email : WebSite : City : Ahmedabad, Ahmedabad Pin Code : 382415 State : Gujarat, India Contact No. : 079- - 29292559, 65447413, GST No. : Company Registration No. : About Company Contact Person : Santram B. Yadav Mobile No. : 9376102361, 9377177197, Contact Person : Mobile No. : , , Contact Person : Mobile No. : , , Truck Available : Services : Daily Service :-Gujarat, Maharashtra, Karnataka, Rajasthan, U.P., Bihar & All Over India '

我想對字符串進行拆分,以便可以在各自的列中獲取諸如電子郵件,網站,城市,個人識別碼等數據。 我嘗試使用re.split但是字符串中有多個Contact Person值。

如何區分它們?

所以我要做的是:

new = data["info"].str.split("Email :|Address |WebSite :|City :|Pin Code :|State :|Contact No. :|GST No. :|Company Registration No. :|Contact Person :|Mobile No. :|Truck Available :|Services :|Service :", expand=True)

然后將new的元素分配給數據

data["Address"] = new[1]
data["Email"] = new[2]
data["Website"] = new[3]
data["City"] = new[4]
data["Pin Code"] = new[5]

像這樣。 而對於多個聯系人,我做到了

data["Contact person 1"] = new[10]
data["p1_contact_no"] = new[11]
data["Contact person 2"] = new[12]
data["p2_contact_no"] = new[13]
data["Contact person 3"] = new[14]
data["p3_contact_no"] = new[15]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM