话题水军识别应用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.5 KiB

  1. #coding:utf8
  2. import json
  3. import pymysql
  4. import traceback
  5. import pandas as pd
  6. # content_db = pymysql.connect(host='172.26.28.30', user='crawl', passwd='crawl123', db='test', port=3306,
  7. # charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor)
  8. # def to_mysql(sql,values):
  9. # content_db.ping(reconnect=True)
  10. # cursor = content_db.cursor()
  11. # cursor.execute(sql,values)
  12. # content_db.commit()
  13. # cursor.close()
  14. #
  15. #
  16. # def write_data_mysql():
  17. # data=pd.read_csv('reply_file.csv',keep_default_na=False)
  18. # for i in data.index:
  19. # # line_key=list(data.loc[i].keys())
  20. # line_value=data.loc[i].values
  21. # # line_str=([str(x) for x in line_value])
  22. # line_str=[]
  23. # for index,x in enumerate(line_value):
  24. # line_str.append(x)
  25. # line_str=[0]+line_str
  26. # sql = "insert into reply_file "+"values ("+ ','.join(['%s'] * len(line_str)) + ")"
  27. # # print(line_str)
  28. # # print(sql)
  29. # values=tuple(line_str)
  30. # # print(values)
  31. # to_mysql(sql,values)
  32. # print('第%s条数据写入mysql'%(i+1))
  33. #
  34. # write_data_mysql()
  35. # content_db.close()
  36. # a=[{"name":"ll","age":23},{"name":"ii","age":21}]
  37. # b=pd.DataFrame(a)
  38. # 创建示例 DataFrame
  39. df = pd.DataFrame({'id': [1, 2, 3], 'name': ['John', 'Alice', 'Bob'],'age':['23','34','45']})
  40. # df1={1:['John','23'],2:['Alice','34'],3:['Bob','45']}
  41. # result_dict = df.set_index('id')['name'].to_dict()
  42. df1 = df.set_index('id')[['name', 'age']].T.to_dict()
  43. print(df1)