Getting “TypeError: loc must be int” when trying to insert() a column

As your trace error says, you need to use int for loc. Now you use numpy.int64 which is not an pure int type in python. Please, try:

first_val = int(df[df.loc[0]=="Density"].index[0])

As a result type(first_val) gives int.

But be careful, if your df is extremely large. Simple int range is between (0 to 4294967295) and np.uint64 has range between (0 to 18446744073709551615)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top