exp_100.py 957 B

123456789101112131415161718192021222324252627282930313233
  1. import pandas as pd
  2. import dataset
  3. import json
  4. import pymysql
  5. pymysql.install_as_MySQLdb()
  6. # df = pd.read_csv(r"C:\/Users\/s1301\/Documents\/關鍵字建議.csv",engine='python')
  7. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
  8. # table=db['seo_jobs']
  9. table=db['selected_kw']
  10. f = open("/Users/mac/Downloads/456.csv")
  11. df = pd.read_csv(f,header=None, names=['id','cust','plan','json','is_nda','term'])
  12. df=df.fillna('')
  13. for index,row in df.iterrows():
  14. print(row)
  15. parsed_data = json.loads(row['json'])
  16. id = row['id']
  17. cust = row['cust']
  18. plan = row['plan']
  19. kw = parsed_data['prefix']
  20. domain = parsed_data['domain']
  21. # table.insert({'cust':'','plan':'形象SEO','json':json})
  22. table.insert({'term':kw,'client':cust,'domain':domain})
  23. # table.insert({'term': row['kw'], 'client': client, 'url': row['url']})
  24. db.close()
  25. ####先從雲端下載csv 再用記事本打開另存一個csv#########