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']]]
CodePudding user response:
Seems like you use DataFrame.reindex method with wrong syntax.
Here an example from link
df.reindex(new_index, fill_value=0)
CodePudding user response:
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