Python Pandas : How to skip columns when reading a file?

后端 未结 2 624
暖寄归人
暖寄归人 2021-01-03 22:42

I have table formatted as follow :

foo - bar - 10 2e-5 0.0 some information
quz - baz - 4 1e-2 1 some other description in here

When I open

2条回答
  •  悲哀的现实
    2021-01-03 23:15

    If you are using Linux/OS X/Windows Cygwin, you should be able to prepare the file as follows:

    cat your_file |  cut -d' ' -f1,2,3,4,5,6,7 > out.file
    

    Then in Python:

    a = pd.read_table("out.file", header=None, sep=" ")
    

    Example:

    Input:

    foo - bar - 10 2e-5 0.0 some information
    quz - baz - 4 1e-2 1 some other description in here
    

    Output:

    foo - bar - 10 2e-5 0.0
    quz - baz - 4 1e-2 1
    

    You can run this command manually on the command-line, or simply call it from within Python using the subprocess module.

提交回复
热议问题