0

I am new to Python, coming from MATLAB. In MATLAB, I used to create a variable table (copy from excel to MATLAB) in MATLAB and save it as a .mat file and whenever I needed the data from the MATLAB, I used to import it using:

A = importdata('Filename.mat'); 

[Filename is 38x5 table, see the attached photo]

Is there a way I can do this in Python? I have to work with about 35 such tables and loading everytime from excel is not the best way.

petezurich
  • 9,280
  • 9
  • 43
  • 57
Pradeep
  • 15
  • 1
  • 1
  • 6
  • Possible duplicate of [Read .mat files in Python](https://stackoverflow.com/questions/874461/read-mat-files-in-python) – Framester Oct 01 '18 at 11:45

2 Answers2

0

Use pandas:

import pandas as pd
dataframe = pd.read_csv("your_data.csv")
dataframe.head() # prints out first rows of your data

Or from Excel:

dataframe = pd.read_excel('your_excel_sheet.xlsx')
petezurich
  • 9,280
  • 9
  • 43
  • 57
  • As far as I am concerned the excel import is called with pd.Excelfile('your_excel_sheet.xlsx') ... https://www.datacamp.com/community/tutorials/python-excel-tutorial – Pablo Jeken Rico Oct 01 '18 at 11:54
  • Is there not an easy way like in MATLAB where I can just copy tables from excel to python and save it as a .py file – Pradeep Oct 01 '18 at 12:07
0

In order to import excel tables into your python environment you have to install pandas. Check out the detailed guideline.

import pandas as pd
xl = pd.ExcelFile('myFile.xlsx')

I hope this helps.

petezurich
  • 9,280
  • 9
  • 43
  • 57
Pablo Jeken Rico
  • 569
  • 5
  • 22