内容涉及:文件遍历,读取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 - util - GenericParameterizedBundle

    https://mp.weixin.qq.com/s/vf0PfjbxQ3Ywjk6tk85SfA   介绍GenericParameterizedBundle的实现.   ​​   1. 基本介绍 ...

  2. fix元素居中

    今天的一个面试题,我是这么写的: div{ position:fixed; margin:auto; left:; right:; top:; bottom:; width:200px; height ...

  3. Java实现 蓝桥杯VIP 算法训练 连接字符串

    算法训练 连接字符串 时间限制:1.0s 内存限制:512.0MB 编程将两个字符串连接起来.例如country与side相连接成为countryside. 输入两行,每行一个字符串(只包含小写字母, ...

  4. Java实现 洛谷 P1914 小书童——密码

    import java.util.Scanner; public class Main { private static Scanner cin; public static void main(St ...

  5. java实现第四届蓝桥杯逆波兰表达式

    逆波兰表达式 正常的表达式称为中缀表达式,运算符在中间,主要是给人阅读的,机器求解并不方便. 例如:3 + 5 * (2 + 6) - 1 而且,常常需要用括号来改变运算次序. 相反,如果使用逆波兰表 ...

  6. 【JAVA习题二十九】809*??=8*??+9*??+1 其中??代表的两位数,8*??的结果为两位数,9*??的结果为3位数。求??代表的两位数,及809*??后的结果。

    package erase; public class 八九与问好两位数的乘积和 { public static void main(String[] args) { int m,n;//m十位,n个 ...

  7. Spring zuul 快速入门实践 --看zuul如何进行服务转发

    zuul 作为springCloud 的全家桶组件之一,有着不可或缺的分量.它作为一个普通java API网关,自有网关的好处: 避免将内部信息暴露给外部: 统一服务端应用入口: 为微服务添加额外的安 ...

  8. SimpleDateFormat 和 Calendar 对于时间的处理

    import java.text.SimpleDateFormat;import java.util.Date;public class test { public static void main( ...

  9. Python Opencv-contrib Camshift&kalman卡尔曼滤波&CSRT算法 目标跟踪实现

    本次课题实现目标跟踪一共用到了三个算法,分别是Camshift.Kalman.CSRT,基于Python语言的Tkinter模块实现GUI与接口设计,项目一共包含三个文件: main.py: # co ...

  10. css如何实现水平垂直居中

    方法 居中元素定宽高固定 PC兼容性 移动端兼容性 absolute + 负margin 是 ie6+, chrome4+, firefox2+ 安卓2.3+, iOS6+ absolute + ma ...