话题水军识别应用
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.
 

47 lines
1.5 KiB

#coding:utf8
import json
import pymysql
import traceback
import pandas as pd
# content_db = pymysql.connect(host='172.26.28.30', user='crawl', passwd='crawl123', db='test', port=3306,
# charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor)
# def to_mysql(sql,values):
# content_db.ping(reconnect=True)
# cursor = content_db.cursor()
# cursor.execute(sql,values)
# content_db.commit()
# cursor.close()
#
#
# def write_data_mysql():
# data=pd.read_csv('reply_file.csv',keep_default_na=False)
# for i in data.index:
# # line_key=list(data.loc[i].keys())
# line_value=data.loc[i].values
# # line_str=([str(x) for x in line_value])
# line_str=[]
# for index,x in enumerate(line_value):
# line_str.append(x)
# line_str=[0]+line_str
# sql = "insert into reply_file "+"values ("+ ','.join(['%s'] * len(line_str)) + ")"
# # print(line_str)
# # print(sql)
# values=tuple(line_str)
# # print(values)
# to_mysql(sql,values)
# print('第%s条数据写入mysql'%(i+1))
#
# write_data_mysql()
# content_db.close()
# a=[{"name":"ll","age":23},{"name":"ii","age":21}]
# b=pd.DataFrame(a)
# 创建示例 DataFrame
df = pd.DataFrame({'id': [1, 2, 3], 'name': ['John', 'Alice', 'Bob'],'age':['23','34','45']})
# df1={1:['John','23'],2:['Alice','34'],3:['Bob','45']}
# result_dict = df.set_index('id')['name'].to_dict()
df1 = df.set_index('id')[['name', 'age']].T.to_dict()
print(df1)