擅长:python、mysql、java
<p>尝试将Regex与<code>str.extract</code>一起使用。你知道吗</p>
<p><strong>例如:</strong></p>
<pre><code>df = pd.DataFrame({'address':["Arnie Morton's of Chicago 435 S. La Cienega Blvd. Los Angeles 310-246-1501 Steakhouses",
"Art's Deli 12224 Ventura Blvd. Studio City 818-762-1221 Delis",
"Bel-Air Hotel 701 Stone Canyon Rd. Bel Air 310-472-1211 French Bistro"]})
df[["address", "phone_number", "category"]] = df["address"].str.extract(r"(?P<address>.*?)(?P<phone_number>\b\d{3}\-\d{3}\-\d{4}\b)(?P<category>.*$)")
print(df)
</code></pre>
<p><strong>输出:</strong></p>
<pre><code> address phone_number \
0 Arnie Morton's of Chicago 435 S. La Cienega Bl... 310-246-1501
1 Art's Deli 12224 Ventura Blvd. Studio City 818-762-1221
2 Bel-Air Hotel 701 Stone Canyon Rd. Bel Air 310-472-1211
category
0 Steakhouses
1 Delis
2 French Bistro
</code></pre>
<p><strong>注意:</strong>:假设地址的内容总是<code>address phone_number category</code></p>