Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to extract list of element based on list index (Not pandas default index)

How can I extract the first, second, and 3rd elements from all rows? There are 4217 rows.

Here is my code:

0       [38, 24, 35]
1       [38, 24, 35]
2       [34, 24, 35]
3       [34, 26, 38]
4       [34, 26, 38]
        ...     
4212    [34, 27, 35]
4213    [35, 32, 38]
4214    [34, 27, 35]
4215    [32, 24, 34]
4216    [37, 29, 39]
Name: element_size, Length: 4217, dtype: object

I tried this df.element_size[0] but only got this [38, 24, 35]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can do

pd.DataFrame(df['elements'].tolist())

For asscess the single item in list

df['elements'].str[0]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading