0

When I print out my list it prints as

[array([7], dtype=int64), 
 array([11], dtype=int64), 
 array([15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, 67], dtype=int64)]

But I want it like [7,11,15,19,23, ...]

I am using pandas to get the index value of columns which matches certain conditions, in 1st 2 conditions the values were unique hence it gives output array array([7], dtype=int64), array([11], dtype=int64), but then one of the condition is matched by multiple index value of columns hence it produces array([15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, 67])

But I want it as a list of numbers as [7,11,15,19,23, ...]

So what can I do?

Here is my code

dy= df.xs(0)
for id in dy:
    if 'ID' in str(id):
        #ID list Index Values
        zr= dy[dy==id].index.value 
        zr_list = zr_list.append(zr)
        print(zr_list)

Output

     [array([7], dtype=int64), 
     array([11], dtype=int64), 
     array([15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, 67], 
     dtype=int64)]

1 Answers1

1

Use extend() instead of append(), as this answer makes abundantly clear. Change your line that uses append to:

zr_list = zr_list.extend(zr)

In short:

  • append: appends the list as a single element to the original list
  • extend: appends the list element by element to the original list
UJIN
  • 1,648
  • 13
  • 28