Home > OS >  Print list object in column using pandas
Print list object in column using pandas

Time:11-22

I have code which produces a CSV by printing as shown below

 array_all = {'Hand': [alldata], 'Pose':[keypoints], 'Face Pose': [face_position]}
        df = pd.DataFrame(
            array_all
        )
        df.to_csv('test.csv',
                  mode='w',
                  index=False,
                  header=True)

To give context to how these objects are created, here's the code for one of the objects, all objects are using the same structure

        face_position = []
        for data_point in results.face_landmarks.landmark:
            if 0.6 <= data_point.x < 0.8:
                face_position.append('Straight')
            else:
                face_position.append('Angled')

        print(face_position)

Here the face_landmarks refers to objects created from the mediapipe library(enter image description here

However, I want it to look like this

enter image description here

CodePudding user response:

In this line of code:

array_all = {'Hand': [alldata], 'Pose':[keypoints], 'Face Pose': [face_position]}

You are creating nested lists in each of your columns. Do not forget that alldata, keypoints and face_position are already lists.

Instead of the above, do the following:

array_all = {'Hand': alldata, 'Pose':keypoints, 'Face Pose': face_position}
  • Related