02 Aug

Import Matlab Data

Some data that is provided by universities appears as a .mat file. These file type is unique to matplotlib and can be imported via the io function in the Scipy Python package. See an example below using the Forset Cover dataset.

Import Prelimnaries

In [1]:
# Import Modules
import pandas as pd
from scipy import io

# Set Pandas Configuration
pd.set_option('max_columns', 1000)
pd.set_option('max_rows', 1000)

Import MAT File

In [2]:
# Import Mat File
data = io.loadmat('Data/ForestCover/cover.mat')

# Create Dataframe of the File
df = pd.concat([pd.DataFrame(data['X']), pd.DataFrame(data['y'], columns=['target'])], axis =1)
df.head()
Out[2]:
0 1 2 3 4 5 6 7 8 9 target
0 2804 139 9 268 65 3180 234 238 135 6121 0
1 2785 155 18 242 118 3090 238 238 122 6211 0
2 2579 132 6 300 -15 67 230 237 140 6031 0
3 2886 151 11 371 26 5253 234 240 136 4051 0
4 2742 134 22 150 69 3215 248 224 92 6091 0

Author: Kavi Sekhon