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

Chris Parry
  • 2,937
  • 7
  • 30
  • 71

1 Answers1

53

try rows = df.index.values instead

user3404344
  • 1,707
  • 15
  • 13