如何读取 csv 文件并更改所需文件夹的目录

How do I read a csv file and change the needed folders' directory

我有一个数据集,其中包含约 148,000 个视频文件夹,每个文件夹都转换为大约平均 30 帧的帧。

我有 2 个 csv 文件用于训练和验证。我已经能够通过以下代码创建一个注释文件来标记我需要的数据。


import numpy as np
import pandas as pd
import os

Dir = "./DataSet/20bn-jester-v1/"

classes = ['No gesture', 'Thumb Down', 'Thumb Up','Swiping Down', 'Swiping Up', 'Swiping Left', 'Swiping Right' ]

class_dict = {k: v for v, k in enumerate(classes)}

#Will count frames in each example

def count_frame(folder_name):
    return len([frame for frame in os.listdir(Dir+str(folder_name)) if os.path.isfile(os.path.join(Dir+str(folder_name), frame))])

#reading training csv

df = pd.read_csv('DataSet/jester-v1-train.csv',sep=';',header=None)

# Getting the data for only selected classes
df = df[df[1].isin(classes)]

# Convert class labels into int value(Encoding)
df[3] = df[1].map(class_dict).astype(str)

# Apply the Count frame function and store the data in column 2
df[2] = df[0].apply(count_frame).astype(int)

# Re arrange the columns
# Where column 0 is folder name, column 1 is start frame, column 2 is end frame and column 3 is label
df = df[[0, 1, 2, 3]]

# setting column 1 values equal to 1
df[1] = 1

df

这给了我以下结果。

我做同样的验证。我只是不知道如何使用以下信息并将第 0 列中的以下文件分隔到一个单独的文件夹中,因为我想将其上传到 google 驱动器,但由于文件数量和我的互联网作为土豆,我无法将整个数据集上传到驱动器

编辑:我已经 tar 压缩文件并尝试将其上传到 google 驱动器。有没有办法解压文件名在文本文件中的特定文件?

好的,所以我设法使用了第 0 列并将其保存为 csv 文件,并且使用以下代码从一个目录复制到另一个目录

import pandas as pd
from shutil import copyfile
import os, shutil


src_directory = "test1/"
dest_directory = "test2/"

df = pd.read_csv('list.csv',sep=';',header= None)
for fileName in df[0]:
    src_file = src_directory + str(fileName)
    dest_file = dest_directory + str(fileName)
    shutil.copytree(src_file, dest_file)