-->
当前位置:首页 > DayDayUp > 正文内容

python excel读取示例

Luz1年前 (2023-10-09)DayDayUp1466

#coding:utf-8
import pandas as pd
import requests
import os
import random
# 读取Excel文件
excel_file = input('输入文件名:')
df = pd.read_excel(excel_file)
folder_name='save_img'
os.makedirs(folder_name, exist_ok=True)
indexx=0
# 遍历数据行
for index, row in df.iterrows():
    plate_number = row['车牌号码']
    capture_time = row['抓拍时间']
    location = row['抓拍地点']
    composite_image_url = row['合成图']
    overpass_image_urls = [row['过车图片'], row['过车图片1'], row['过车图片2'], row['过车图片3']]
    print(composite_image_url,overpass_image_urls)
    # 创建文件夹以保存图片
    #folder_name = f"{plate_number}_{capture_time.replace(':', '-')}_{location.replace(' ', '_')}"
    
    #try:
    # 下载合成图
    if 'nan' not in str(composite_image_url):
        composite_image_response = requests.get(composite_image_url)
        if composite_image_response.status_code == 200:
            composite_image_filename = os.path.join(folder_name, f"{plate_number}_composite{str(indexx)}.jpg")
            with open(composite_image_filename, 'wb') as f:
                f.write(composite_image_response.content)
            print(f"下载合成图成功:{composite_image_filename}")
            indexx+=1
    #except:
      #      print('发生错误:',composite_image_url)
    
    # 下载过车图片
    for i, overpass_image_url in enumerate(overpass_image_urls):
        #try:
        if 'nan' not in str(overpass_image_url):
            overpass_image_response = requests.get(overpass_image_url)
            if overpass_image_response.status_code == 200:
                overpass_image_filename = os.path.join(folder_name, f"{plate_number}_overpass_{i+1} {str(indexx)}.jpg")
                with open(overpass_image_filename, 'wb') as f:
                    f.write(overpass_image_response.content)
                print(f"下载过车图片成功:{overpass_image_filename}")
                indexx+=1
        #except:
        #    print('发生错误:',overpass_image_url)

读取表格指定列的url,下载并保存url文件


发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。