用python读取excel文件并批量生成SQL然后写入到txt文件里面

# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""

import numpy as np
import pandas as pd
import os
os.chdir('C:/Users/dell-3020/Desktop/')

df = pd.read_excel('100.xlsx')
#print(type(data))#
t = df.head(5000)
#print(data)
#t = pd.DataFrame(data) #
#print(t)
#print(t['account_number'])
path =  'C:\\Users\\dell-3020\\Desktop\\100.txt'
f = open(path, 'w', encoding = 'utf8')

for i in t.index:
    #上面的直接用str就可以,下面的不行
   c = 'update contract_info set money='+t.loc[i]['money'].__str__()+' where contract_number='+'\''+t.loc[i]['account_number']+'\''+';'
   #print(c)  
   f.write(c+'\n')
f.close()

你可能感兴趣的:(python)