当前位置:网站首页>Modify CSV
Modify CSV
2022-07-26 01:08:00 【Falling gold】
import os
import csv
images, labels = [], []# Initialize two list Arrays are stored separately csv Image path and label in the file
with open('val.csv') as f:# Read in the original csv file
reader = csv.reader(f)
for row in reader:
img, label = row# Assign the read content of each line to a new variable
images.append(img)# Add the read image path to list Array
labels.append(label)# Add the read label to the list Array
images_new=[]# Initialize a new one list Array is used to store new picture paths
labels_new=[]
for i in range(len(labels)):
images_split=images[i].split('/')# Use here split Division , according to split('/') After segmentation, a new list Array
# Get file name , Replace with a new address prefix
image=images_split[7]
images_new.append('../LeviCDVOC/JPEGImages/val/'+image)
labels_split=labels[i].split('/')# Use here split Division , according to split('/') After segmentation, a new list Array
# Get file name , Replace with a new address prefix
label=labels_split[7]
labels_new.append('../LeviCDVOC/SegementationClass/val/'+image)
import numpy as np
import pandas as pd
save_name = 't.csv'
jpgfilename = np.array([file for file in images_new], dtype=object)
dataframe = pd.DataFrame(jpgfilename.reshape(len(jpgfilename), 1))
jpgfilename = np.array([file for file in labels_new], dtype=object)
dataframe.insert(loc=1,column=1,value=jpgfilename.reshape(len(jpgfilename), 1))
dataframe.to_csv(save_name, encoding='utf-8', index=False, header=False, mode='a+')I want to modify it csv There are two columns of data
Before the change :

After modification :

边栏推荐
- [Code] refers to the repeated number in the offer 03 array
- Open download! Alibaba Devops Practice Manual
- How can MySQL just duplicate data?
- Nanjie's embarrassment
- 【RTOS训练营】程序框架、预习、课后作业和晚课提问
- # 浏览器开发使用技巧
- Embedded development: tips and tricks -- seven tips for designing powerful boot loader
- 【软件开发规范三】【软件版本命名规范】
- Tencent employees' salary: the real 985 graduation salary, do you think I can be saved? Netizen: daily salary?
- [RTOS training camp] continue the program framework, tick interrupt supplement, preview, after-school homework and evening class questions
猜你喜欢

NLP introduction + practice: Chapter 3: gradient descent and back propagation

代理IP服务器如何保证自身在网络中的信息安全呢

C language_ The use and implementation of string comparison function StrCmp

【纪中】2022.7.16 1432.输油管道

【RTOS训练营】任务调度(续)、任务礼让、调度总结、队列和晚课提问

Nanjie's embarrassment

Download exclusively | Alibaba cloud maxcompute questions and answers to unlock SaaS mode cloud data warehouse in this electronic manual!

985高校副教授晒年薪,公积金顶普通人月薪,网友:不愧是在上海

Sqli-labs Less7

全国一半人跑长沙,长沙一半人跑哪?
随机推荐
[RTOS training camp] equipment subsystem, questions of evening students
Matlab bitwise and or not
Timeout settings for feign and hystrix
【RTOS训练营】站在更高的角度学习C语言
健身房一年关店8000家,逆势盈利的工作室是怎么开的?
【RTOS训练营】环形缓冲区、AT指令、预习安排和晚课提问
REST-assured接口测试框架详解
Jupyter changes the main interface and imports the dataset
Working principle of ZK rollups
Small sample learning data set
Android SQLite first groups and then sorts left concatenated queries
Django database addition, deletion, modification and query
El table scroll bar settings
[RTOS training camp] program framework, preview, after-school homework and evening class questions
[RTOS training camp] review of the previous section, idle tasks, timer tasks, execution sequence, scheduling strategy and evening class questions
如何mysql只要重复数据?
How can MySQL just duplicate data?
《nlp入门+实战:第三章:梯度下降和反向传播 》
NLP introduction + practice: Chapter 4: using pytorch to manually realize linear regression
JDBC connection database (idea version)