Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read file with space separated values in pandas

Tags:

python

pandas

csv

I try to read the file into pandas. The file has values separated by space, but with different number of spaces I tried:

pd.read_csv('file.csv', delimiter=' ') 

but it doesn't work

like image 970
yemu Avatar asked Oct 28 '13 10:10

yemu


People also ask

How do you get rid of trailing spaces in pandas?

Strip Space in column of pandas dataframe (strip leading, trailing & all spaces of column in pandas) str. strip() function is used to remove or strip the leading and trailing space of the column in pandas dataframe.

How do I read a .TXT file in pandas?

We can read data from a text file using read_table() in pandas. This function reads a general delimited file to a DataFrame object. This function is essentially the same as the read_csv() function but with the delimiter = '\t', instead of a comma by default.


1 Answers

add delim_whitespace=True argument, it's faster than regex.

like image 189
HYRY Avatar answered Sep 22 '22 11:09

HYRY