I work with pretty dirty data: a tariff table with the following form:
import pandas as pd
import numpy as np
data1 = np.array([u'Free (A, B, KR, FR), 5% (JP)', u'Free (A, B, FR), 5% (JP, KR))'])
data2 = np.array(['10101010', '10101020'])
data = {'hscode': data2, 'tariff' : data1}
df = pd.DataFrame(data, columns=['hscode', 'tariff'])
The first line shows that for countries (A, B, KR, FR) the tariff is zero, and for JP it is 5%, and the second line shows that for A, B, FR it is zero, and for JP it is 5% KR.
I want to find the tariff rate of the country “KR” for each row so that I can have the following table:
'hscode' 'tariff'
10101010 0%
10101020 5%
So, I want to find the tariff rate for the county code "KR" in each cell.
source
share