简道云成员id与字段监控分离
This commit is contained in:
+17
-9
@@ -122,6 +122,7 @@
|
||||
"} # 衡时数据库链接配置-mysql\n",
|
||||
"table_name = \"thailand_store_data_email\" # 请替换为实际的表名\n",
|
||||
"# table_name = \"yida_process_time_statistics\"\n",
|
||||
"\n",
|
||||
"# 连接\n",
|
||||
"connection = mysql.connector.connect(\n",
|
||||
" host=HS_DB_Config[\"host\"],\n",
|
||||
@@ -130,12 +131,12 @@
|
||||
" database=HS_DB_Config[\"database\"]\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"print(f\"成功连接 {HS_DB_Config[\"database\"]}\")\n",
|
||||
"print(f\"成功连接 {HS_DB_Config['database']}\")\n",
|
||||
"cursor = connection.cursor()\n",
|
||||
"\n",
|
||||
"# 读取Excel文件\n",
|
||||
"df = pd.read_excel(\n",
|
||||
" r\"C:\\Users\\Administrator.DESKTOP-7IC2USJ\\Downloads\\门店日使用数据Workshop’s_Daily_Usage_Data_20250805101517.xlsx\",\n",
|
||||
" r\"C:\\Users\\Administrator.DESKTOP-7IC2USJ\\Downloads\\门店日使用数据Workshop's_Daily_Usage_Data_20250805101517.xlsx\",\n",
|
||||
" sheet_name=\"Sheet1\")\n",
|
||||
"\n",
|
||||
"# 处理空值 - 将NaN/NaT/空字符串统一转为None\n",
|
||||
@@ -146,16 +147,23 @@
|
||||
"placeholders = ', '.join(['%s'] * len(df.columns))\n",
|
||||
"insert_query = f\"INSERT INTO {table_name} ({columns}) VALUES ({placeholders})\"\n",
|
||||
"\n",
|
||||
"# 批量插入数据\n",
|
||||
"# 批量插入数据,每次1000条\n",
|
||||
"records = [tuple(row) for row in df.values]\n",
|
||||
"cursor.executemany(insert_query, records)\n",
|
||||
"connection.commit()\n",
|
||||
"batch_size = 1000\n",
|
||||
"total_records = len(records)\n",
|
||||
"inserted_count = 0\n",
|
||||
"\n",
|
||||
"print(f\"成功导入 {cursor.rowcount} 条记录到 {table_name} 表\")\n",
|
||||
"for i in range(0, total_records, batch_size):\n",
|
||||
" batch = records[i:i+batch_size]\n",
|
||||
" cursor.executemany(insert_query, batch)\n",
|
||||
" connection.commit()\n",
|
||||
" inserted_count += len(batch)\n",
|
||||
" print(f\"已成功导入 {inserted_count}/{total_records} 条记录\")\n",
|
||||
"\n",
|
||||
"print(f\"总共成功导入 {inserted_count} 条记录到 {table_name} 表\")\n",
|
||||
"\n",
|
||||
"cursor.close()\n",
|
||||
"\n",
|
||||
"connection.close()\n"
|
||||
"connection.close()"
|
||||
],
|
||||
"id": "a98f8dd324b53eeb",
|
||||
"outputs": [
|
||||
@@ -407,7 +415,7 @@
|
||||
{
|
||||
"metadata": {},
|
||||
"cell_type": "markdown",
|
||||
"source": "## 删除区间数据",
|
||||
"source": "### 删除区间数据",
|
||||
"id": "8192d432b3f65bc2"
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user