Read Space-separated Data With Pandas
I used to read my data with numpy.loadtxt(). However, lately I found out in SO, that pandas.read_csv() is much more faster. To read these data I use: pd.read_csv(filename, sep=' '
Solution 1:
Your original line:
pd.read_csv(filename, sep=' ',header=None)
was specifying the separator as a single space, because your csvs can have spaces or tabs you can pass a regular expression to the sep
param like so:
pd.read_csv(filename, sep='\s+',header=None)
This defines separator as being one single white space or more, there is a handy cheatsheet that lists regular expressions.
Post a Comment for "Read Space-separated Data With Pandas"