0

I'm a total beginner at Python. I've got multiple csv files for different video outputs stored in different folders.

1st: I want Python to read in all the csv files. Works with the following code:

frames = []
indices = []

for folder in os.listdir(path):
    for file in os.listdir(path+folder):
        if 'faces' in file and 'FrameLevel' in file:
#           print(file)
            df = pd.read_csv(path+'/'+folder+'/'+file)
            vid = file[:12]
            print(vid)
            indices.append(vid)
            df.insert(0,'vid',vid)
            frames.append(df)

This is how the dataframe looks like then: df

2nd: I want Python to read every csv file and a add new rows every 2nd row with specific values. So I want to extend every csv file in order to add new information. E.g. for video file V2ID_35_0638. The "New" first (0) row would look like this: V2ID_35_0638, 180.0, 5.0, 0 The 2nd (1) row would be the "old" first (0) row: V2ID_35_0638, 360.0, 10.0, 0 The 3rd row (2) would then be V2ID_35_0638, 580.0, 15.0, 0 The 4th row (3) would be the "old" 2nd (1) row: V2ID_35_0638, 760.0, 20.0, 0 ...

The 'vid' will always stay the same, 'time' increases by 400.0, frame increase by 10.

I hope you get what I mean.

Best

  • Does this answer your question? [Is it possible to insert a row at an arbitrary position in a dataframe using pandas?](https://stackoverflow.com/questions/15888648/is-it-possible-to-insert-a-row-at-an-arbitrary-position-in-a-dataframe-using-pan) – Roim Sep 05 '20 at 12:37
  • But how can I do this for every 2nd row not a specific one? Probably with a for loop? – Mister Data Sep 05 '20 at 12:46
  • 1
    yes, you'll have to use a for loop. Another option is to change indices of original dataframe, merge it by index with a dataframe fill of how you want (where every indices will be as you want) and then sort it by index – Roim Sep 05 '20 at 12:57

0 Answers0