擅长:python、mysql、java
<p>不是那么花哨,但应该做这项工作:</p>
<pre><code>import pandas as pd
#convert dfType dataframe to dictionary
type_dict = dfType.set_index('ITEM/CODE').T.to_dict()
#function that takes in DESC column value and outputs corresponding value from type_dict
def map_type(in_str):
out_str = np.NaN
for val in in_str.split():
if val in type_dict.keys():
out_str = type_dict[val]['TYPE']
return out_str
#apply above function to DESC column
dfInput['CLASSIFICATION'] = dfInput['DESC'].apply(map_type)
</code></pre>