Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
地址验证Python_Python_Oracle_Python 2.7 - Fatal编程技术网

地址验证Python

地址验证Python,python,oracle,python-2.7,Python,Oracle,Python 2.7,我遇到了数据重复本身而不是在下面的脚本中循环的问题。如何让脚本从api中为每一行提供正确的地址 [我的代码]:也请原谅糟糕的代码布局。我是个笨蛋 下面是我目前得到的。如何让脚本从api中为每一行提供正确的地址 请专注于你问题中的问题。我们关心的是您想要验证地址,而不是糟糕的地址对您的业务流程的影响。这不再是编程领域了。明白了,Klaus D。我只是想确保你们所有的专家都了解业务需求和问题的各个方面,但我会尽最大努力避免不必要的失误。我会编辑这篇文章,把主要问题放在最上面。那么你真正的问题是什么呢

我遇到了数据重复本身而不是在下面的脚本中循环的问题。如何让脚本从api中为每一行提供正确的地址

[我的代码]:也请原谅糟糕的代码布局。我是个笨蛋

下面是我目前得到的。如何让脚本从api中为每一行提供正确的地址


请专注于你问题中的问题。我们关心的是您想要验证地址,而不是糟糕的地址对您的业务流程的影响。这不再是编程领域了。明白了,Klaus D。我只是想确保你们所有的专家都了解业务需求和问题的各个方面,但我会尽最大努力避免不必要的失误。我会编辑这篇文章,把主要问题放在最上面。那么你真正的问题是什么呢?把问题分解一下,你也可能想看看
'''
This is a tool to pull address data from a db, validate the extracted 
addresses, and save the updated addresses to Excel for the DBAs to update
'''
#Modules used
import cx_Oracle #Connect to the Oracle db and pull the data
import lob #The api that does the address validation (https://lob.com)
import pandas as pd

#Lob API key received by signing up at the Lob website
lob.api_key = '<key>'

#SQL script to display the open orders and their addresses
sqlscript = '''
        select order_number,
               address1,
               address2,
               city,
               state,
               postcode,
               country
        from orders_table
        '''
#Connect to the database 
con = cx_Oracle.connect('un/pw@db')
cur = con.cursor()
cur.execute(sqlscript)

# Create dataframe from SQL
columns = [desc[0] for desc in cur.description]

#I'm using cur.fetchmany(2) for testing so I'm not hitting the db for 40k 
#rows everytime; once this script is validated, will 
#change to fetchall()

data = cur.fetchmany(2)
df1 = pd.DataFrame(list(data), columns=columns)

'''
The rest of this script is a struggle for me. 
'''
for order_number,address1,address2,city,state,postcode,country in dataOld:
  verifiedAddress = lob.Verification.create(
      address_line1 = address1,
      address_line2 = address2,
      address_city = city,
      address_state = state,
      address_zip = postcode,
      address_country = country
    )

row1 = verifiedAddress.address.address_line1
row2 = verifiedAddress.address.address_line2
row3 = verifiedAddress.address.address_city
row4 = verifiedAddress.address.address_state
row5 = verifiedAddress.address.address_zip

idx2 = 2
df1.insert(idx2, "updated_address1", row1)
idx4 = 4
df1.insert(idx4, "updated_address2", row2)
idx6 = 6
df1.insert(idx6, "updated_city", row3)
idx8 = 8
df1.insert(idx8, "updated_state", row4)
idx10 = 10
df1.insert(idx10, "updated_zip", row5)

#print df1

writer = pd.ExcelWriter('garbage.xlsx')
df1.to_excel(writer, sheet_name='extract')
writer.save()

print 'File creation complete'
cur.close()
con.close()