内容涉及:文件遍历,读取csv指定列,拷贝文件,清理和创建文件

# -*- coding: utf-8 -*-
import csv
import os
import sys
import numpy as np
import copy
import shutil
import pandas as pd
from collections import Counter
from shutil import copyfile '''
原数据目录如下:
./2019-6-14/
├── 1816740
│ ├── IMG005x020.csv
│ ├── IMG027x033.JPG
│ ├── IMG029x023.csv
│ └── IMG029x023.JPG
... ...
├── 1816765
│ └── ... ...
├── 1816875
│ └── ... ...
├── 1816896
│ └── ... ...
├── 1816900
│ └── ... ...
└── 1816969
└── ... ...
...
分类脚本与/2019-6-14/在同级目录
''' data = '2019-6-23'
path = os.getcwd()
path_1 = path + '/' + data
data_N_root = path + '/' + 'data_N' + '_' + data
data_P_root = path + '/' + 'data_P' + '_' + data
if os.path.exists(data_N_root):
shutil.rmtree(data_N_root+'/')
os.mkdir(data_N_root)
if os.path.exists(data_P_root):
shutil.rmtree(data_P_root+'/')
os.mkdir(data_P_root)
print("清理文件夹")
print(data_N_root)
print(data_P_root)
list_name = os.listdir(path_1)
lossfile = []
count1 = 0
count2 = 0
for n in list_name:
path_2 = path_1 + '/' + n
list_name_1 = os.listdir(path_2)
for m in list_name_1:
temp = copy.copy(m[-3:])
temp_1 = copy.copy(m[:-3])
csv_root = path_1 + '/' + n + '/' + m if temp == 'csv':
if not os.path.exists(csv_root[:-3] + 'JPG'):
lossfile.append(csv_root)
continue
with open(csv_root,'rwb') as csvfile:
reader = csv.reader(csvfile)
column1 = [row[0]for row in reader]
column1 = column1[1:]
#print("len",len(column1))
column2 = str(np.ones((len(column1),1)))
print(column1)
print(column2)
print(csv_root)
writer = csv.writer(csvfile)
for val in column2:
writer.writerow('type',val)
print("cell type :", column1)
sign = 0
for k in column1:
if k == '' or k == '':
continue
else:
sign = 1
print("sign :", sign)
if sign == 1:
print("该FOV为阳性")
copyfile(csv_root[:-3] + 'csv',data_P_root + '/' + temp_1 + 'csv')
copyfile(csv_root[:-3] + 'JPG',data_P_root + '/' + temp_1 + 'JPG')
count1 = count1 + 1
else:
print("该FOV为阴性")
copyfile(csv_root[:-3] + 'csv',data_N_root + '/' + temp_1 + 'csv')
copyfile(csv_root[:-3] + 'JPG',data_N_root + '/' + temp_1 + 'JPG')
count2 = count2 + 1 print("===============================")
if len(lossfile) == 0:
print("data classify OK")
else:
print("loss file :")
for n in lossfile:
print(n)
print("阳性FOV数量:",count1)
print("阴性FOV数量:",count2)

python文件处理-根据csv文件内容,将对应图像拷贝到指定文件夹的更多相关文章

  1. Shell 命令行 从日志文件中根据将符合内容的日志输出到另一个文件

    Shell 命令行 从日志文件中根据将符合内容的日志输出到另一个文件 前面我写了一篇博文Shell 从日志文件中选择时间段内的日志输出到另一个文件,利用循环实现了我想要实现的内容. 但是用这个脚本的同 ...

  2. 使用matlab批量处理图像后在指定文件夹存储

    使用matlab批量处理图像后在指定文件夹存储 clear;clc;close all; Files=dir('D:\文件及下载相关\文档\MATLAB\postgraduate\Kodak\*.jp ...

  3. android源码编译时拷贝替换指定文件

    由于要做版本定制,某些版本的资源文件等(例如style.xml)需要不同的配置,但是android的编译开关无法在xml里使用,于是想到了编译时根据不同的编译开关编译不同的文件,如下: 1.建立A.x ...

  4. 【.Net 学习系列】-- FileSystemWatcher 监控文件夹新生成文件,并在确认文件没有被其他程序占用后将其移动到指定文件夹

    监控文件夹测试程序: using System; using System.Collections.Generic; using System.IO; using System.Linq; using ...

  5. Linux下find一次查找多个指定类型文件,指定文件或者排除某类文件,在 GREP 中匹配多个关键 批量修改文件名等

    http://blog.sina.com.cn/s/blog_62e7fe670101dg9d.html linux下二进制文件查找: strings 0000.ts | grep -o " ...

  6. 使用find命令按条件查找多个文件并且拷贝至指定目录

    命令格式如下 find / \( -name "*.war" -o -name "*.jar" \) | xargs -i cp {} ${wardir} 当需 ...

  7. sourcetree .git 强制忽略指定文件不提交

    在公司写项目,大部分都会用到 svn 或 git 提交代码到服务器.我们公司用的GIT,每个程序员有自己的独立分支,各写各的代码互不冲突,最终合并到主分支再解决相同代码冲突问题.这时候会遇到一些配置文 ...

  8. C# 通过物理路径将文件以二进制保存到指定文件夹

    /// <summary> /// 通过物理路径将文件以二进制保存到指定文件夹 /// </summary> /// <param name="filePath ...

  9. Windows下make clean指令错误[错误码2](系统找不到指定文件)的解决方案

    问题来源 因为笔者想用GCC编译器进行Windows下的C语言编程,安装了Mingw-w64的x86_64-posix-seh版本,并按照Visual Studio Code官方的教程,将Mingw- ...

随机推荐

  1. Rocket - tilelink - Edges

    https://mp.weixin.qq.com/s/UggNsNOeEMP-GhzlLiT-qQ   简单介绍Edges的实现.   ​​   1. TLEdge   包含client和manage ...

  2. Rocket - decode - 几个问题

    https://mp.weixin.qq.com/s/pMsK_E4mQrm3QXdnp7nDPQ   讨论指令解码部分遗留的几个问题.     1. 最小项与蕴含项之间的关系   参考链接: htt ...

  3. jchdl - RTL实例 - MOS6502 ALU (Verilog)

    https://mp.weixin.qq.com/s/jLUz757FQZjMEYzYb2AIww   MOS6502是简单,但是曾经相当流行的一款CPU.网上有很多模拟程序可供学习使用.这里使用一个 ...

  4. js函数中的this关键字

    关于这个this关键字,也是很多项目中常常被用到的,那么,有人也许会问,干嘛要用this呢,在函数被调用时,直接指明是什么对象在调用不就行了?还整那么个模模糊糊的概念出来干嘛?不过嘛,存在即真理,既然 ...

  5. 使用Python代码制作GIF动态图

    使用Python  PIL.Image 制作GIF图片: import  PIL.Image                      相关模块 img = Image.open(img_name)  ...

  6. Java实现 蓝桥杯 算法提高 宰羊

    试题 算法提高 宰羊 资源限制 时间限制:1.0s 内存限制:256.0MB 问题描述 炫炫回了内蒙,肯定要吃羊肉啦,所有他家要宰羊吃. 炫炫家有N只羊,羊圈排成一排,标号1~N.炫炫每天吃掉一只羊( ...

  7. 第六届蓝桥杯JavaC组省赛真题

    解题代码部分来自网友,如果有不对的地方,欢迎各位大佬评论 题目1.隔行变色 隔行变色 Excel表的格子很多,为了避免把某行的数据和相邻行混淆,可以采用隔行变色的样式. 小明设计的样式为:第1行蓝色, ...

  8. Java实现One-way traffic(单向交通)

    One-way traffic In a certain town there are n intersections connected by two- and one-way streets. T ...

  9. java实现第七届蓝桥杯凑平方数

    凑平方数 把0~9这10个数字,分成多个组,每个组恰好是一个平方数,这是能够办到的. 比如:0, 36, 5948721 再比如: 1098524736 1, 25, 6390784 0, 4, 28 ...

  10. js数据劫持 Object.defineProperty() 作用

    原生js Object.defineProperty() 作用 假设我们有一个obj对象,我们要给他设置一个name属性会这么做 Object.defineProperty()也可以设置对象属性 这个 ...