Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 851
Chris Parry Avatar asked Jun 22 '16 03:06

Chris Parry


1 Answers

try rows = df.index.values instead

like image 138
user3404344 Avatar answered Nov 16 '22 03:11

user3404344