22

I am isolating some row ids from a Pandas dataframe, like this:

data = df.loc[df.cell == id]
rows = df.index

print(type(rows))
< class 'pandas.indexes.numeric.Int64Index'>

I want to convert rows to a numpy array so I can save it to a mat file using sio.savemat. This is returning an error though:

row_mat = rows.as_matrix()
AttributeError: 'Int64Index' object has no attribute 'as_matrix'

What is the correct way, please? Thanks

1 Answer 1

53

try rows = df.index.values instead

Sign up to request clarification or add additional context in comments.

1 Comment

I think the OP wanted df.loc[df.cell == id].index.values. If they confirm, you can update your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.