data_dir = 'D:\\Project\\test\\picture\\data.csv' #数据路径 df = pd.read_csv(data_dir,header = None) #读取csv文件 df_name = df.iloc[:,0] #索引得到图片名 df_label = df.iloc[:,1] #得到label label = [] for i,name in enumerate(df_name): n = df_label[i].split('[')[1].split(']')[0] #通过切片方式把【】中的数字取出 label.append(n) #with open(os.path.join(r"D:\项目\转正\picture\label",name.split('.')[0] + ".txt"),'w') as fp: #fp.write(df_label[i].split('[')[1].split(']')[0]) print(label) with open("label.csv", "a", newline='', encoding='utf-8') as file: writer = csv.writer(file ,delimiter=',') writer.writerows(label)
06-29
1229
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-09
1444
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
02-23
2022
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交