擅长:python、mysql、java
<pre><code>import pandas as pd
import numpy as np
df1 = pd.DataFrame(['green apple and banana are sweet fruits','how fresh is the banana','cherry from japan'],columns=['fruits_names'])
df2 = pd.DataFrame([['green apple|opal apple','red'],['banana|cavendish banana','yellow'],['cherry','black']],columns=['fruits','colors'])
df2['sep_colors'] = np.where(df2['fruits'], (df2['fruits'].str.split(pat='|')), df2['fruits'])
dic = dict(zip(df2['colors'].tolist(),df2['sep_colors'].tolist()))
final = []
for row in range(len(df1.fruits_names)):
list1 = []
for key, value in dic.items():
for item in value:
if item in df1.iloc[row][0]:
list1.append(key)
final.append(list1)
df1['colors'] = final
</code></pre>