0

I have a dataframe whose index is made of strings representing paths towards uniquely ID'ed videos across different directories, as in the following example:

>>> df
                           class
path                            
dir1/video_id1/frame1.jpg      1
dir1/video_id1/frame2.jpg      1
dir1/video_id1/frame3.jpg      1
dir2/video_id2/frame1.jpg      1
dir2/video_id2/frame2.jpg      1
dir2/video_id2/frame3.jpg      1
dir2/video_id3/frame1.jpg      0
dir2/video_id3/frame2.jpg      0
dir2/video_id3/frame3.jpg      0 

I also have a list of videos I want to keep for testing as follows:

test_videos = ["dir2/video_id3", "dir1/video_id1"]

I would like to extract another dataframe whose rows correspond to the paths of the frames of the videos appearing in the list test_videos, such that the final dataframe looks like:

>>> test_df
                           class
path                            
dir1/video_id1/frame1.jpg      1
dir1/video_id1/frame2.jpg      1
dir1/video_id1/frame3.jpg      1
dir2/video_id3/frame1.jpg      0
dir2/video_id3/frame2.jpg      0
dir2/video_id3/frame3.jpg      0 
JoJolyne
  • 45
  • 2
  • 5

0 Answers0