To convert a Pandas Int64Index
to a numpy array, you can use the to_numpy()
method instead of as_matrix()
, as as_matrix()
has been deprecated. Here’s how you can do it:
pythonimport numpy as np
row_mat = rows.to_numpy()
This will convert the Int64Index
object rows
to a numpy array row_mat
, which you can then use with sio.savemat
to save it to a mat file.
المزيد من المعلومات
بالطبع! في الكود الذي قدمته، أولاً تقوم بعزل بعض معرفات الصفوف من إطار البيانات Pandas باستخدام df.loc[df.cell == id]
وتخزينها في متغير rows
باستخدام df.index
. ثم تستخدم print(type(rows))
لطباعة نوع الكائن rows
الذي يكون pandas.indexes.numeric.Int64Index
.
بعد ذلك، تحاول تحويل rows
إلى مصفوفة numpy باستخدام rows.as_matrix()
، ولكن هذه الطريقة قد تكون قديمة وقد تمت إزالتها، ولكن يمكنك بسهولة استخدام to_numpy()
بدلاً من ذلك.
باستخدام to_numpy()
، يمكنك تحويل rows
إلى مصفوفة numpy بنجاح واستخدامها في وظيفة sio.savemat
لحفظها في ملف mat كما تريد.