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 isolate an item from a list that is part of a Series

Hello I have a panda series named t1 that looks like this:

print(t1)

0         [21, 45]
1         [09, 45]
3         [19, 30]
4         [08, 00]
5         [23, 00]
            ...   
136935    [08, 20]
136936    [10, 20]
136937    [00, 15]
136938    [21, 00]
136939    [20, 05]

each row consists of a list with 2 items and I am trying to isolate the first item from each list and append it to an array but I am getting the error: IndexingError: Too many indexers

For example I know I can isolate the first item from the first row (’21’) using the iloc like this (which works):

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

t1.iloc[0][0][:]

but I get the error IndexingError: Too many indexers when I try to put it in a for loop and try to append it to a new arrary which I dont understand.

arr = []
for i in t1.iteritems():
    arr.append(t1.iloc[i][0][:])

Hopefully someone can assist because I am lost. The code works outside a for loop but in the for loop I get the error.

>Solution :

Use .str[0]:

arr = t1.str[0].tolist()
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