当前位置:网站首页>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 :

边栏推荐
- RHCE之at和crontab命令详解及chrony部署
- C language_ The use and implementation of string comparison function StrCmp
- [RTOS training camp] course learning methods and C language knowledge (pointer, structure, function pointer, linked list) and student questions
- Android SQLite first groups and then sorts left concatenated queries
- How to copy and paste QT? (QClipboard)
- 【RTOS训练营】晚课学员问题
- Failed to load DLL
- Sqli-labs Less7
- Suddenly found an optimization artifact
- Centrosymmetric binary mode cslbp, matlab
猜你喜欢

NLP introduction + practice: Chapter 4: using pytorch to manually realize linear regression

【ctf】Crypto初步基础概要

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

Detailed explanation of rest assured interface testing framework

How accurate is the IP address? What are dynamic IP and static IP? The most common method of switching IP

How to choose social e-commerce model in the early stage? Taishan crowdfunding
![[software development specification III] [software version naming Specification]](/img/dd/86f3323591ec688d6828d7075db59d.png)
[software development specification III] [software version naming Specification]

Lock upgrade: no lock, bias lock, lightweight lock, heavyweight lock

Detailed explanation of at and crontab commands of RHCE and deployment of Chrony

Nanjie's embarrassment
随机推荐
109. Upload local files using SAP ui5 fileuploader control
android sqlite先分组后排序左连查询
REST-assured接口测试框架详解
[RTOS training camp] continue the program framework, tick interrupt supplement, preview, after-school homework and evening class questions
Codeforces Round #810 (Div. 2)A~C
Subarray with 19 and K
matlab 移位操作基础
Timeout settings for feign and hystrix
[secsha concept] original reverse supplement
【RTOS训练营】任务调度(续)、任务礼让、调度总结、队列和晚课提问
We have no way out
matlab 按位 与 或 非
985高校副教授晒年薪,公积金顶普通人月薪,网友:不愧是在上海
Unityvr robot Scene 3 gripper
Diablo: immortality mobile game how to open more brick moving and novice introduction brick moving strategy
[RTOS training camp] program framework, preview, after-school homework and evening class questions
If the native family is general, and the school is also a college on the rotten street, how to go on the next journey
Open download! Alibaba Devops Practice Manual
【RTOS训练营】GPIO知识和预习安排 + 晚课提问
[CTF] crypto preliminary basic outline