Value travel in columns

0

I have the following dataframe:

and I want to go through each line of the column "CO_tin_no" to consult it with a webservice

item=[]

for nit in mydataset_df.CO_tin_no:
    nit = mydataset_df.CO_tin_no
    url = 'http://www.rues.org.co/RM/ConsultaNIT_json'

    headers, payload = {
            'Content-Type':
            'application/x-www-form-urlencoded; charset=UTF-8'
        }, {'txtNIT': nit}
    r = requests.post(url, headers=headers, data=payload, timeout=4)
    if r.json().get('rows', False):
        res = r.json()['rows'][0]
        legal_name = res['razon_social'].title()
        item.append(legal_name)
        #print item
        mydataset_df['legal_name'] = item

    else:
        response = 'no se encuentra el nit o cc ->'
        mydataset_df['legal_name'] = response
        #print response, nit

mydataset_df['legal_name'] = item

This function stops when it does not get a registration in the webservice and the validation does not continue.

The response error is:

ValueError: Length of values does not match length of index
    
asked by Yan Chirino 16.10.2018 в 18:39
source

0 answers