0

Can someone help me where I got it wrong

data_pad = []
for key in np.unique(df['unique-key']):
    data_pad += [df[df.reindex[:, 'unique-key'] == key].reindex[:, ['distance', 'direction', 'gridID']]]
Gundler
  • 9
  • 1
  • 2
    `reindex` is a method. It should be called with `()`, putting the arguments inside the parentheses. – khelwood Dec 26 '21 at 10:13
  • 1
    Does this answer your question? ['method' object is not subscriptable. Don't know what's wrong](https://stackoverflow.com/questions/35261055/method-object-is-not-subscriptable-dont-know-whats-wrong) – Joe Dec 26 '21 at 10:19

2 Answers2

0

Seems like you use DataFrame.reindex method with wrong syntax.

Here an example from link

df.reindex(new_index, fill_value=0)

Yevhen Bondar
  • 4,357
  • 1
  • 11
  • 31
0

Let's understand the error. First - what subscriptable mean? Here you can find detailed answer but in general it means object can be called with [] syntax

l = [1,2,3]
print(l[0]) # works, l is subscriptable
x = 5
print(x[0]) # TypeError: 'int' object is not subscriptable

We are close, so now we know that we use [] on object that is not subscriptable, and as error says, that object is method

class A:
    def my_method(self, param):
        print(param)


a = A()
a.my_method(0) # prints 0
a.my_method[0] # TypeError: 'method' object is not subscriptable

Voila! We can now suspect our problem is because we use some method with square brackets instead of classic one. As other suggested, it's reindex method

kosciej16
  • 6,294
  • 1
  • 18
  • 29