Read tab-delimited fields with pandas, some lines with more than one tabs

后端 未结 2 628
粉色の甜心
粉色の甜心 2021-01-22 03:20

I am trying to read a tab separated txt file using Pandas. The file looks like this:

data file sample

14.38   14.21   0.8951  5.386   3.312   2.462   4.9         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-22 03:37

    Pandas read_csv is very versatile, you can use it with delim_whitespace = True to handle variable number of whitespaces.

    df = pd.read_csv(filename, delim_whitespace=True)
    

    Option 2: Use separator argument

    df = pd.read_csv(filename, sep='\t+')
    

提交回复
热议问题