我有一个案例研究,需要从retail中获取数据,使用聚合函数、联接等对数据进行一些分析,并使用JSON格式的响应数据绘制一些零售图。
目前正在采取的做法如下:
如果有人可以建议最好的方法(如python中的预处理或后处理)来处理这样的场景,这将是有帮助的。
def store_data(AccountNo)
db=MySQLdb.connect(host=HOST, user=USER, passwd=PASSWD, db=DATABASE, charset="utf8")
cursor = db.cursor()
insert_query = "INSERT INTO cstore (AccountNo) VALUES (%s)"
cursor.execute(insert_query, (AccountNo))
db.commit()
cursor.close()
db.close()
return
def on_data(file_path):
#This is the meat of the script...it connects to your mongoDB and stores the tweet
try:
# Decode the JSON from Twitter
testFile = open(file_path)
datajson = json.load(testFile)
#print (len(datajson))
#grab the wanted data from the Tweet
for i in range(len(datajson)):
for cosponsor in datajson[i]:
AccountNo=cosponsor['AccountNo']
store_data( AccountNo)发布于 2018-04-04 13:52:10
为了提高数据加载的性能,可以做以下几件事情:
LOAD DATA从文件(示例)加载。这可能是最快的方式去做你想要做的事情。.executemany()代替.execute():datajson = json.load(testFile) insert_query =“”插入cstore (AccountNo)值(%(AccountNo)s)“cursor.executemany(insert_query,datajson)”ujsonumysql Python数据库驱动程序中也取得了一些与数据加载性能相关的成功,但是看起来这个包已经有很长一段时间没有维护了。https://codereview.stackexchange.com/questions/191162
复制相似问题