Convert class 'pandas.indexes.numeric.Int64Index' to numpy

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

try rows = df.index.values instead

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like