194 lines
23 KiB
Plaintext
194 lines
23 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-05-06T08:07:37.987318Z",
|
|
"start_time": "2025-05-06T08:07:37.981570Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"import warnings\n",
|
|
"warnings.filterwarnings(\"ignore\")"
|
|
],
|
|
"id": "5d8950bc",
|
|
"outputs": [],
|
|
"execution_count": 1
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-05-06T09:04:50.848572Z",
|
|
"start_time": "2025-05-06T09:04:50.837245Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"import requests\n",
|
|
"\n",
|
|
"# 读取Excel文件\n",
|
|
"file_path = '车衣短地址测试.xlsx'\n",
|
|
"df = pd.read_excel(file_path)\n",
|
|
"\n",
|
|
"# 高德地图API Key\n",
|
|
"api_key = 'f61b09d406ac49f8a034bf585e60c442'"
|
|
],
|
|
"id": "29f0d8c5a906c478",
|
|
"outputs": [],
|
|
"execution_count": 6
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-05-06T09:15:53.529156Z",
|
|
"start_time": "2025-05-06T09:15:51.678696Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"import requests\n",
|
|
"\n",
|
|
"# 读取Excel文件\n",
|
|
"file_path = '车衣短地址测试.xlsx'\n",
|
|
"df = pd.read_excel(file_path)\n",
|
|
"\n",
|
|
"# 高德地图API Key\n",
|
|
"api_key = 'f61b09d406ac49f8a034bf585e60c442'\n",
|
|
"# 存储电话号码的列表\n",
|
|
"phone_numbers = []\n",
|
|
"all_data = []\n",
|
|
"for index, row in df.iterrows():\n",
|
|
" province = row['省']\n",
|
|
" city = row['市']\n",
|
|
" district = row['区/县']\n",
|
|
" address = row['地址']\n",
|
|
" shop_name = row['门店店名']\n",
|
|
" new_name = f\"{address}{shop_name}\"\n",
|
|
"\n",
|
|
" # 构建搜索URL\n",
|
|
" search_url = f\"https://restapi.amap.com/v3/place/text?keywords={new_name}&city={city}&children=1&output=json&key={api_key}\"\n",
|
|
"\n",
|
|
" # 发送请求\n",
|
|
" response = requests.get(search_url)\n",
|
|
" data = response.json()\n",
|
|
" #df=pd.DataFrame(data)\n",
|
|
" #df.to_csv('output.csv')\n",
|
|
" pois = data.get(\"pois\",[])\n",
|
|
" if len(pois)==0:\n",
|
|
" print(f\"未找到门店店名:{shop_name}\")\n",
|
|
" continue\n",
|
|
" for poi in pois:\n",
|
|
" poi.update({\"shop_name\":row['门店店名']})\n",
|
|
" all_data.append(poi)\n",
|
|
" \n",
|
|
"df = pd.DataFrame(all_data)\n",
|
|
"df.to_csv(\"pois.csv\",index=False)\n"
|
|
],
|
|
"id": "e9e6bcce271944c2",
|
|
"outputs": [],
|
|
"execution_count": 15
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-05-06T09:01:59.385885Z",
|
|
"start_time": "2025-05-06T09:01:59.380866Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"df = pd.read_csv('pois.csv')\n",
|
|
"\n"
|
|
],
|
|
"id": "7ed76ff04dc70a6b",
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"{'suggestion': {'keywords': [], 'cities': []}, 'count': '18', 'infocode': '10000', 'pois': [{'parent': [], 'address': '丁卯新区谷阳路65号', 'distance': [], 'pname': '江苏省', 'importance': [], 'biz_ext': {'cost': [], 'rating': '4.2'}, 'biz_type': [], 'cityname': '镇江市', 'type': '汽车服务;汽车养护/装饰;汽车养护', 'photos': [{'title': [], 'url': 'http://store.is.autonavi.com/showpic/7fbb22496b30ae6d58e0699a33eaed49'}, {'title': [], 'url': 'http://store.is.autonavi.com/showpic/ddd8e94ea67490151feb530257dda3d0'}], 'typecode': '010400', 'shopinfo': '1', 'poiweight': [], 'childtype': [], 'adname': '京口区', 'name': '阿鑫贴膜', 'location': '119.490050,32.177893', 'tel': '18552508047', 'shopid': [], 'id': 'B0KK9ZR10I'}, {'parent': [], 'address': '禹山路32号', 'distance': [], 'pname': '江苏省', 'importance': [], 'biz_ext': {'cost': [], 'rating': '4.2'}, 'biz_type': [], 'cityname': '镇江市', 'type': '汽车服务;汽车养护/装饰;汽车养护', 'photos': [{'title': [], 'url': 'http://store.is.autonavi.com/showpic/0367af90925533afef7c4a4398f8d3c5'}], 'typecode': '010400', 'shopinfo': '1', 'poiweight': [], 'childtype': [], 'adname': '京口区', 'name': 'VF青蛙贴膜改色中心', 'location': '119.487360,32.218423', 'tel': '13024353333;18806106901', 'shopid': [], 'id': 'B0J237B8GA'}, {'parent': [], 'address': '勤政路119-36号', 'distance': [], 'pname': '江苏省', 'importance': [], 'biz_ext': {'cost': [], 'rating': '4.0'}, 'biz_type': [], 'cityname': '镇江市', 'type': '汽车服务;汽车养护/装饰;汽车养护', 'photos': [{'title': [], 'url': 'http://store.is.autonavi.com/showpic/c63e5f84b7b7ece6c6ecd6ee46065d1b'}, {'title': [], 'url': 'http://store.is.autonavi.com/showpic/2865905b317212105ddddef5b02e7074'}, {'title': [], 'url': 'http://store.is.autonavi.com/showpic/b062b0b7e9e120d7ea9cc61a11df92e8'}], 'typecode': '010400', 'shopinfo': '1', 'poiweight': [], 'childtype': [], 'adname': '丹徒区', 'name': '皖北贴膜', 'location': '119.435728,32.136197', 'tel': '15955232779', 'shopid': [], 'id': 'B0JGMH4S4B'}, {'parent': 'B0FFLJRCKD', 'address': '上路新区北门卓酷贴膜工作室', 'distance': [], 'pname': '江苏省', 'importance': [], 'biz_ext': {'cost': [], 'rating': '4.0'}, 'biz_type': [], 'cityname': '镇江市', 'type': '生活服务;生活服务场所;生活服务场所', 'photos': [{'title': [], 'url': 'http://store.is.autonavi.com/showpic/7b6f292dd30782d149210d4bade0eff2'}], 'typecode': '070000', 'shopinfo': '1', 'poiweight': [], 'childtype': '320', 'adname': '句容市', 'name': '卓酷贴膜工作室', 'location': '119.158226,31.927748', 'tel': [], 'shopid': [], 'id': 'B0KGAAM9C8'}, {'parent': [], 'address': '焦山路京岘家园20栋4-11号', 'distance': [], 'pname': '江苏省', 'importance': [], 'biz_ext': {'cost': [], 'rating': '4.1'}, 'biz_type': [], 'cityname': '镇江市', 'type': '汽车服务;汽车养护/装饰;汽车养护', 'photos': [{'title': [], 'url': 'http://store.is.autonavi.com/showpic/5c1cfc535f26c66c19bf42131d72c605'}], 'typecode': '010400', 'shopinfo': '0', 'poiweight': [], 'childtype': [], 'adname': '京口区', 'name': '华尊汽车贴膜', 'location': '119.479305,32.197704', 'tel': '18706100137', 'shopid': [], 'id': 'B0FFHXQPWN'}, {'parent': [], 'address': '南门大街观音桥巷老红旗小学后大门6栋102', 'distance': [], 'pname': '江苏省', 'importance': [], 'biz_ext': {'cost': [], 'rating': '3.4'}, 'biz_type': [], 'cityname': '镇江市', 'type': '生活服务;美容美发店;美容美发店', 'photos': [{'title': [], 'url': 'http://store.is.autonavi.com/showpic/53216112b1f3a72d1894228ef9edd36b'}], 'typecode': '071100', 'shopinfo': '0', 'poiweight': [], 'childtype': [], 'adname': '京口区', 'name': '爱慕发型工作室(永安路店)', 'location': '119.456612,32.204181', 'tel': [], 'shopid': [], 'id': 'B01FF02A5T'}, {'parent': [], 'address': '白云街6-11号商铺', 'distance': [], 'pname': '江苏省', 'importance': [], 'biz_ext': {'cost': [], 'rating': '3.9'}, 'biz_type': [], 'cityname': '镇江市', 'type': '生活服务;美容美发店;美容美发店', 'photos': [{'title': [], 'url': 'http://store.is.autonavi.com/showpic/5f72295f431feaf64b53f434e1521744'}, {'title': [], 'url': 'http://store.is.autonavi.com/showpic/783165b51f3dc56211e56078fcb03d04'}], 'typecode': '071100', 'shopinfo': '1', 'poiweight': [], 'childtype': [], 'adname': '丹阳市', 'name': '阿尔工作室', 'location': '119.571520,31.993715', 'tel': [], 'shopid': [], 'id': 'B0J3K1Q56I'}, {'parent': [], 'address': '云阳新村西2门旁', 'distance': [], 'pname': '江苏省', 'importance': [], 'biz_ext': {'cost': [], 'rating': '3.6'}, 'biz_type': [], 'cityname': '镇江市', 'type': '生活服务;美容美发店;美容美发店', 'photos': [{'title': [], 'url': 'http://store.is.autonavi.com/showpic/60b69a24559bffd23ef9b5861dbe5eab'}, {'title': [], 'url': 'http://store.is.autonavi.com/showpic/6df7ee931ee4641291c6798863bbc734'}, {'title': [], 'url': 'http://store.is.autonavi.com/showpic/b7b127099b9b2b86df31586964da0348'}], 'typecode': '071100', 'shopinfo': '0', 'poiweight': [], 'childtype': [], 'adname': '丹阳市', 'name': '利群工作室', 'location': '119.584493,31.991618', 'tel': '13615262219', 'shopid': [], 'id': 'B0FFHJ1TRA'}, {'parent': [], 'address': '新兴路与南环路交叉口北100米', 'distance': [], 'pname': '江苏省', 'importance': [], 'biz_ext': {'cost': [], 'rating': '4.3'}, 'biz_type': [], 'cityname': '镇江市', 'type': '汽车服务;汽车养护/装饰;汽车养护', 'photos': [{'title': [], 'url': 'http://store.is.autonavi.com/showpic/24afea3961c7a27cda455dbd40259cf4'}], 'typecode': '010400', 'shopinfo': '0', 'poiweight': [], 'childtype': [], 'adname': '丹阳市', 'name': '追光汽车维修贴膜中心', 'location': '119.813750,32.064733', 'tel': [], 'shopid': [], 'id': 'B0K2HAHWM8'}, {'parent': [], 'address': '宁杭南路与长龙山路交叉口东北200米', 'distance': [], 'pname': '江苏省', 'importance': [], 'biz_ext': {'cost': [], 'rating': '3.3'}, 'biz_type': [], 'cityname': '镇江市', 'type': '汽车服务;汽车养护/装饰;汽车养护|汽车服务;洗车场;洗车场', 'photos': [], 'typecode': '010400|010500', 'shopinfo': '0', 'poiweight': [], 'childtype': [], 'adname': '句容市', 'name': '洗车贴膜', 'location': '119.171447,31.929271', 'tel': [], 'shopid': [], 'id': 'B0L6FU6WHQ'}, {'parent': [], 'address': '云阳街道全福路164-36号', 'distance': [], 'pname': '江苏省', 'importance': [], 'biz_ext': {'cost': [], 'rating': []}, 'biz_type': [], 'cityname': '镇江市', 'type': '生活服务;生活服务场所;生活服务场所', 'photos': [{'title': [], 'url': 'http://store.is.autonavi.com/showpic/4efc6a596b924dc1fefa1f19a5c3a51d'}, {'title': [], 'url': 'http://store.is.autonavi.com/showpic/545e3b6444943690b9319765b981f72a'}], 'typecode': '070000', 'shopinfo': '0', 'poiweight': [], 'childtype': [], 'adname': '丹阳市', 'name': '7²工作室', 'location': '119.579659,31.994544', 'tel': [], 'shopid': [], 'id': 'B0KR5OR5A4'}, {'parent': [], 'address': '曲阿路与迎春路交叉口东北160米', 'distance': [], 'pname': '江苏省', 'importance': [], 'biz_ext': {'cost': [], 'rating': '3.8'}, 'biz_type': [], 'cityname': '镇江市', 'type': '汽车服务;汽车养护/装饰;汽车养护', 'photos': [{'title': [], 'url': 'http://store.is.autonavi.com/showpic/289c134ef693387a0e0e9e12fb20fcc3'}, {'title': [], 'url': 'http://store.is.autonavi.com/showpic/ec439823acf36a21eafa15d1cd3cd0e2'}], 'typecode': '010400', 'shopinfo': '0', 'poiweight': [], 'childtype': [], 'adname': '丹阳市', 'name': '膜匠专业车身贴膜', 'location': '119.595060,32.006459', 'tel': '15862962757', 'shopid': [], 'id': 'B0FFHHELB5'}, {'parent': [], 'address': '经济技术开发区大泊镇中路75号(信鸽通讯和千家惠旁)', 'distance': [], 'pname': '江苏省', 'importance': [], 'biz_ext': {'cost': [], 'rating': '3.7'}, 'biz_type': [], 'cityname': '镇江市', 'type': '生活服务;维修站点;维修站点', 'photos': [{'title': [], 'url': 'http://store.is.autonavi.com/showpic/b093169816ec0f7fdbf27ab60ea0dc14'}, {'title': [], 'url': 'http://store.is.autonavi.com/showpic/a709ff77828fd6e69d409478bf92aa30'}, {'title': [], 'url': 'http://store.is.autonavi.com/showpic/cdaea85e226c1c2d26c6476410bb2210'}], 'typecode': '071200', 'shopinfo': '1', 'poiweight': [], 'childtype': [], 'adname': '丹阳市', 'name': '贴膜吧', 'location': '119.597555,32.028363', 'tel': [], 'shopid': [], 'id': 'B0FFIZTJAG'}, {'parent': [], 'address': '云阳镇新市口时尚莱迪后门', 'distance': [], 'pname': '江苏省', 'importance': [], 'biz_ext': {'cost': [], 'rating': '4.0'}, 'biz_type': [], 'cityname': '镇江市', 'type': '生活服务;美容美发店;美容美发店', 'photos': [{'title': [], 'url': 'http://store.is.autonavi.com/showpic/0834d21ef5cd91d7e04f8c990c19db57'}, {'title': [], 'url': 'http://store.is.autonavi.com/showpic/7c4226d14c957fbfd796563173ebdd23'}, {'title': [], 'url': 'http://store.is.autonavi.com/showpic/beba17b8e9e60af8aabe4efcdc93d208'}], 'typecode': '071100', 'shopinfo': '0', 'poiweight': [], 'childtype': [], 'adname': '丹阳市', 'name': '亮点工作室(时尚莱迪店)', 'location': '119.583937,31.991037', 'tel': '13615261400', 'shopid': [], 'id': 'B0FFHEL1U6'}, {'parent': [], 'address': '迎宾大道188号', 'distance': [], 'pname': '江苏省', 'importance': [], 'biz_ext': {'cost': [], 'rating': '3.9'}, 'biz_type': [], 'cityname': '镇江市', 'type': '汽车服务;汽车养护/装饰;汽车养护', 'photos': [{'title': [], 'url': 'http://store.is.autonavi.com/showpic/49bf204614ed20effa57376a56465bfc'}, {'title': [], 'url': 'http://store.is.autonavi.com/showpic/1afbc3b699f8111cf66229ce44569b29'}, {'title': [], 'url': 'http://store.is.autonavi.com/showpic/9be6dc0c4313ef40cace91be1ac6cf25'}], 'typecode': '010400', 'shopinfo': '0', 'poiweight': [], 'childtype': [], 'adname': '扬中市', 'name': '扬中市滨江勤丰汽车贴膜工作室', 'location': '119.835164,32.222453', 'tel': [], 'shopid': [], 'id': 'B0J2DAXWU2'}, {'parent': 'B0FFGAUGJV', 'address': '宝龙大道25号华美嘉园', 'distance': [], 'pname': '江苏省', 'importance': [], 'biz_ext': {'cost': [], 'rating': '3.9'}, 'biz_type': [], 'cityname': '镇江市', 'type': '生活服务;美容美发店;美容美发店', 'photos': [{'title': [], 'url': 'http://store.is.autonavi.com/showpic/8e3701ba2b70487ff3d78d14e2481401'}, {'title': [], 'url': 'http://store.is.autonavi.com/showpic/1bdf2346845e5c71ffba9646a89fd537'}], 'typecode': '071100', 'shopinfo': '0', 'poiweight': [], 'childtype': '320', 'adname': '句容市', 'name': '潮流造型阿磊工作室(华美嘉园店)', 'location': '119.039863,32.144634', 'tel': '18895423995', 'shopid': [], 'id': 'B0FFHG9FU5'}, {'parent': 'B0FFFDTW09', 'address': '丹阳市开发区金陵西路吾悦广场金街(外街小吃街)3号门右侧139北户', 'distance': [], 'pname': '江苏省', 'importance': [], 'biz_ext': {'cost': [], 'rating': '4.8'}, 'biz_type': [], 'cityname': '镇江市', 'type': '生活服务;维修站点;维修站点', 'photos': [{'title': [], 'url': 'https://aos-comment.amap.com/B0JBS5U86Y/comment/4e0c7ef167277967be347ebd3e47a4f3_2048_2048_80.jpg'}, {'title': [], 'url': 'http://store.is.autonavi.com/showpic/687197273fc9dd417ad7e378c5ef7c20'}, {'title': [], 'url': 'http://store.is.autonavi.com/showpic/29d27a444feb034eecdd1fbfadbebc8f'}], 'typecode': '071200', 'shopinfo': '1', 'poiweight': [], 'childtype': '202', 'adname': '丹阳市', 'name': '创泽数码手机维修精致贴膜', 'location': '119.609135,31.996144', 'tel': '13382987987', 'shopid': [], 'id': 'B0JBS5U86Y'}, {'parent': 'B0JB145XVC', 'address': '吾悦广场S5号-129.130', 'distance': [], 'pname': '江苏省', 'importance': [], 'biz_ext': {'cost': [], 'rating': '3.9'}, 'biz_type': [], 'cityname': '镇江市', 'type': '体育休闲服务;运动场馆;健身中心', 'photos': [{'title': [], 'url': 'http://store.is.autonavi.com/showpic/69baadde07b45edd25946667365640db'}], 'typecode': '080111', 'shopinfo': '1', 'poiweight': [], 'childtype': '320', 'adname': '扬中市', 'name': '23号健身私教工作室', 'location': '119.795313,32.219542', 'tel': [], 'shopid': [], 'id': 'B0KG6LXWZ3'}], 'status': '1', 'info': 'OK'}\n"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 3
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-05-06T07:35:18.345916Z",
|
|
"start_time": "2025-05-06T07:35:18.221818Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"phone_number = ''\n",
|
|
"if data['status'] == '1' and len(data['pois']) > 0:\n",
|
|
" # 假设第一个匹配的结果就是目标店铺\n",
|
|
" phone_number = data['pois'][0].get('tel', '')\n",
|
|
"\n",
|
|
"phone_numbers.append(phone_number)\n",
|
|
"\n",
|
|
"# 将电话号码添加到DataFrame中\n",
|
|
"df['电话号码'] = phone_numbers\n",
|
|
"\n",
|
|
"# 保存修改后的Excel文件\n",
|
|
"output_file_path = 'updated_excel_file.xlsx'\n",
|
|
"df.to_excel(output_file_path, index=False)\n",
|
|
"\n",
|
|
"print(f\"电话号码已成功添加到 {output_file_path}\")"
|
|
],
|
|
"id": "192bf9353721068f",
|
|
"outputs": [
|
|
{
|
|
"ename": "ValueError",
|
|
"evalue": "Length of values (1) does not match length of index (18)",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
|
|
"\u001B[1;31mValueError\u001B[0m Traceback (most recent call last)",
|
|
"Cell \u001B[1;32mIn[36], line 9\u001B[0m\n\u001B[0;32m 6\u001B[0m phone_numbers\u001B[38;5;241m.\u001B[39mappend(phone_number)\n\u001B[0;32m 8\u001B[0m \u001B[38;5;66;03m# 将电话号码添加到DataFrame中\u001B[39;00m\n\u001B[1;32m----> 9\u001B[0m df[\u001B[38;5;124m'\u001B[39m\u001B[38;5;124m电话号码\u001B[39m\u001B[38;5;124m'\u001B[39m] \u001B[38;5;241m=\u001B[39m phone_numbers\n\u001B[0;32m 11\u001B[0m \u001B[38;5;66;03m# 保存修改后的Excel文件\u001B[39;00m\n\u001B[0;32m 12\u001B[0m output_file_path \u001B[38;5;241m=\u001B[39m \u001B[38;5;124m'\u001B[39m\u001B[38;5;124mupdated_excel_file.xlsx\u001B[39m\u001B[38;5;124m'\u001B[39m\n",
|
|
"File \u001B[1;32mD:\\anaconda2025\\Lib\\site-packages\\pandas\\core\\frame.py:4311\u001B[0m, in \u001B[0;36mDataFrame.__setitem__\u001B[1;34m(self, key, value)\u001B[0m\n\u001B[0;32m 4308\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_setitem_array([key], value)\n\u001B[0;32m 4309\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[0;32m 4310\u001B[0m \u001B[38;5;66;03m# set column\u001B[39;00m\n\u001B[1;32m-> 4311\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_set_item(key, value)\n",
|
|
"File \u001B[1;32mD:\\anaconda2025\\Lib\\site-packages\\pandas\\core\\frame.py:4524\u001B[0m, in \u001B[0;36mDataFrame._set_item\u001B[1;34m(self, key, value)\u001B[0m\n\u001B[0;32m 4514\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21m_set_item\u001B[39m(\u001B[38;5;28mself\u001B[39m, key, value) \u001B[38;5;241m-\u001B[39m\u001B[38;5;241m>\u001B[39m \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[0;32m 4515\u001B[0m \u001B[38;5;250m \u001B[39m\u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[0;32m 4516\u001B[0m \u001B[38;5;124;03m Add series to DataFrame in specified column.\u001B[39;00m\n\u001B[0;32m 4517\u001B[0m \n\u001B[1;32m (...)\u001B[0m\n\u001B[0;32m 4522\u001B[0m \u001B[38;5;124;03m ensure homogeneity.\u001B[39;00m\n\u001B[0;32m 4523\u001B[0m \u001B[38;5;124;03m \"\"\"\u001B[39;00m\n\u001B[1;32m-> 4524\u001B[0m value, refs \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_sanitize_column(value)\n\u001B[0;32m 4526\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m (\n\u001B[0;32m 4527\u001B[0m key \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mcolumns\n\u001B[0;32m 4528\u001B[0m \u001B[38;5;129;01mand\u001B[39;00m value\u001B[38;5;241m.\u001B[39mndim \u001B[38;5;241m==\u001B[39m \u001B[38;5;241m1\u001B[39m\n\u001B[0;32m 4529\u001B[0m \u001B[38;5;129;01mand\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28misinstance\u001B[39m(value\u001B[38;5;241m.\u001B[39mdtype, ExtensionDtype)\n\u001B[0;32m 4530\u001B[0m ):\n\u001B[0;32m 4531\u001B[0m \u001B[38;5;66;03m# broadcast across multiple columns if necessary\u001B[39;00m\n\u001B[0;32m 4532\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mcolumns\u001B[38;5;241m.\u001B[39mis_unique \u001B[38;5;129;01mor\u001B[39;00m \u001B[38;5;28misinstance\u001B[39m(\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mcolumns, MultiIndex):\n",
|
|
"File \u001B[1;32mD:\\anaconda2025\\Lib\\site-packages\\pandas\\core\\frame.py:5266\u001B[0m, in \u001B[0;36mDataFrame._sanitize_column\u001B[1;34m(self, value)\u001B[0m\n\u001B[0;32m 5263\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m _reindex_for_setitem(value, \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mindex)\n\u001B[0;32m 5265\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m is_list_like(value):\n\u001B[1;32m-> 5266\u001B[0m com\u001B[38;5;241m.\u001B[39mrequire_length_match(value, \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mindex)\n\u001B[0;32m 5267\u001B[0m arr \u001B[38;5;241m=\u001B[39m sanitize_array(value, \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mindex, copy\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mTrue\u001B[39;00m, allow_2d\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mTrue\u001B[39;00m)\n\u001B[0;32m 5268\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m (\n\u001B[0;32m 5269\u001B[0m \u001B[38;5;28misinstance\u001B[39m(value, Index)\n\u001B[0;32m 5270\u001B[0m \u001B[38;5;129;01mand\u001B[39;00m value\u001B[38;5;241m.\u001B[39mdtype \u001B[38;5;241m==\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mobject\u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[1;32m (...)\u001B[0m\n\u001B[0;32m 5273\u001B[0m \u001B[38;5;66;03m# TODO: Remove kludge in sanitize_array for string mode when enforcing\u001B[39;00m\n\u001B[0;32m 5274\u001B[0m \u001B[38;5;66;03m# this deprecation\u001B[39;00m\n",
|
|
"File \u001B[1;32mD:\\anaconda2025\\Lib\\site-packages\\pandas\\core\\common.py:573\u001B[0m, in \u001B[0;36mrequire_length_match\u001B[1;34m(data, index)\u001B[0m\n\u001B[0;32m 569\u001B[0m \u001B[38;5;250m\u001B[39m\u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[0;32m 570\u001B[0m \u001B[38;5;124;03mCheck the length of data matches the length of the index.\u001B[39;00m\n\u001B[0;32m 571\u001B[0m \u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[0;32m 572\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mlen\u001B[39m(data) \u001B[38;5;241m!=\u001B[39m \u001B[38;5;28mlen\u001B[39m(index):\n\u001B[1;32m--> 573\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mValueError\u001B[39;00m(\n\u001B[0;32m 574\u001B[0m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mLength of values \u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[0;32m 575\u001B[0m \u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m(\u001B[39m\u001B[38;5;132;01m{\u001B[39;00m\u001B[38;5;28mlen\u001B[39m(data)\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m) \u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[0;32m 576\u001B[0m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mdoes not match length of index \u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[0;32m 577\u001B[0m \u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m(\u001B[39m\u001B[38;5;132;01m{\u001B[39;00m\u001B[38;5;28mlen\u001B[39m(index)\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m)\u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[0;32m 578\u001B[0m )\n",
|
|
"\u001B[1;31mValueError\u001B[0m: Length of values (1) does not match length of index (18)"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 36
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "code",
|
|
"outputs": [],
|
|
"execution_count": null,
|
|
"source": "",
|
|
"id": "1e5c016e726ce44a"
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.10.9"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|