1

I have a set of videos in different folders. Each time that a video is selected, I want to save some properties of that video file, like the name of the video, its directory, and the number of frames in a csv file. I use pandas dataframe for that, creating a separate csv file for each video. something like this:

import pandas as pd
import os

listOfLabels = pd.DataFrame([])
listOfLabels.append(pd.DataFrame({'video name': os.path.basename(path),
                                  'video path': os.path.dirname(path),
                                  'Number of frames': totalFrameNumber}, 
                                   index=[0]), ignore_index=True)
dirName = 'C:/Users/bert/PycharmProjects/csvFiles'
fileName = os.path.splitext(os.path.basename(path))[0]
fileNameSuffix = 'csv'
csvPathAndName = os.path.join(dirName, fileName + '.' + fileNameSuffix)
listOfLabels.to_csv(csvPathAndName)

where path is the path to the video file, and totalFrameNumber is the number of frames in the video. I know the dirName, fileName, totalFrameNumber, video name, and video path all exist and are correct. The problem is that nothing get appended to the listOfLabels, and although the csv file is created, it is empty. My question is what I am doing wrong when I append the data into listOfLabels.

1 Answer 1

2

.append() doesn't alter the original dataframe in place, it returns a new dataframe with the appended dataframe, well, appended.

It should be

listOfLabels = listOfLabels.append(pd.DataFrame({
    'video name': os.path.basename(path),
    'video path': os.path.dirname(path),
    'Number of frames': totalFrameNumber}, 
    index=[0]), ignore_index=True)

you can ignore the new indentation, the first line just got really long.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.