9
votes

There's a function called importdata on matlab that import data from ASCII files and put it in a structure with 2 variables: textdata and data. It automatically identify the format of data (string, float.. etc), headlines and delimiter. This function comes in handy for me so im searching if have something equivalent in python packages like numpy and scipy. Im using numpy.loadtxt, but sometimes i have to use skiprows,delimiter, usecols and dtype at the same time. Someone knows some function that identify it by a easier way?

1
Did you check numpy's loadtxt? Also there's a scipy.io.loadmat whose documentation states that it "loads MATLAB data files". - Bakuriu
I cited on description that I used numpy.loadtxt as well, but to do it i have to specify skiprows, delimiter, usecols etc.. and in importdata of matlab i use just it, specifying nothing, and it works well identifying skiprows, delimiter, etc automatically. scipy.io.loadmat is for .mat files, not for txt files. It returns "Unknown mat file type". - iury simoes-sousa

1 Answers

3
votes

Looks like pandas http://pandas.pydata.org might be the way to go, if you want a really seamless import. I've seen pandas handle all sorts of strange missing/malformed data gracefully. That said, you do have slightly more complicated data structures than you'd otherwise be looking at.

pandas.read_csv("file")