大型csv文件用什么處理,python指定目錄生成.csv文件_python文件處理-根據csv文件內容,將對應圖像拷貝到指定文件夾...

 2023-10-15 阅读 24 评论 0

摘要:#-*- coding: utf-8 -*-大型csv文件用什么處理?importcsvimportosimportsysimportnumpy as npimportcopyimportshutilimportpandas as pdfrom collections importCounterfrom shutil importcopyfile'''原數據目錄如下:./2019-6-14/├── 1816740│ ├──

#-*- coding: utf-8 -*-

大型csv文件用什么處理?importcsvimportosimportsysimportnumpy as npimportcopyimportshutilimportpandas as pdfrom collections importCounterfrom shutil importcopyfile'''原數據目錄如下:

./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' + '_' +dataifos.path.exists(data_N_root):

shutil.rmtree(data_N_root+'/')

os.mkdir(data_N_root)ifos.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=0for n inlist_name:

path_2= path_1 + '/' +n

list_name_1=os.listdir(path_2)for m inlist_name_1:

temp= copy.copy(m[-3:])

temp_1= copy.copy(m[:-3])

csv_root= path_1 + '/' + n + '/' +mif temp == 'csv':if not os.path.exists(csv_root[:-3] + 'JPG'):

lossfile.append(csv_root)continuewith open(csv_root,'rwb') as csvfile:

reader=csv.reader(csvfile)

column1= [row[0]for row inreader]

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 incolumn2:

writer.writerow('type',val)print("cell type :", column1)

sign=0for k incolumn1:if k == '1' or k == '5':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 inlossfile:print(n)print("陽性FOV數量:",count1)print("陰性FOV數量:",count2)

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/137833.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息