How to store the analyzed dictionary data in the database in Python 3.5
ringa_lee
ringa_lee 2017-05-18 10:59:27
0
2
749
字典是
keywords_dict{}
{'茉莉花茶泡多久': 10, '苦丁长什么样子图片': 5, '茶叶茶加上蜂糖能喝吗': 1, '古丈毛尖多少钱一斤': 29, '干玫瑰花过期': 1}

I am using the database linked to pymysql

The previous statistical data was a single line, so use this

cur.execute('insert into pctongji(yesterday_str, item, question, topic, people, celebrity, brand, category, article) values(%s,%s,%s,%s,%s,%s,%s,%s,%s)', (yesterday_str, category_dict['item'], category_dict['question'], category_dict['topic'], category_dict['people'], category_dict['celebrity'], category_dict['brand'], category_dict['category'], category_dict['article']))
  

Now is how to save multiple rows into the database.
The database has two fields, namely keywords and count, which correspond to the contents in the dictionary above.
How to write the sql statement? What do you want? Deposit as number of days

ringa_lee
ringa_lee

ringa_lee

reply all(2)
左手右手慢动作
    for key in keywords_dict.keys():
        cur.execute('insert into keywords(yesterday_str, keywords, count) values(%s,%s,%s)', (yesterday_str, key, keywords_dict[key]))

Make enough food and clothing by yourself

大家讲道理

It is recommended to use executemany

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template