TypeError: unhashable type: 'slice' for pandas

Viewed 39232

I have a pandas datastructure, which I create like this:

test_inputs = pd.read_csv("../input/test.csv", delimiter=',')

Its shape

print(test_inputs.shape)

is this

(28000, 784)

I would like to print a subset of its rows, like this:

print(test_inputs[100:200, :])
print(test_inputs[100:200, :].shape)

However, I am getting:

TypeError: unhashable type: 'slice'

Any idea what could be wrong?

4 Answers

I was facing the same problem. Even the above solutions couldn't fix it. It was some problem with pandas, What I did was I changed the array into a numpy array that fixed the issue.

import pandas as pd
import numpy as np
test_inputs = pd.read_csv("../input/test.csv", delimiter=',')
test_inputs = np.asarray(test_inputs)
print(test_inputs.values[100:200, :])
print(test_inputs.values[100:200, :].shape)

This code is also working for me.

Related