close

[Solved] Importing text file : No Columns to parse from file

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Importing text file : No Columns to parse from file in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Importing text file : No Columns to parse from file Error Occurs?

Today I get the following error Importing text file : No Columns to parse from file in python.

How To Solve Importing text file : No Columns to parse from file Error ?

  1. How To Solve Importing text file : No Columns to parse from file Error ?

    To Solve Importing text file : No Columns to parse from file Error Using try and except just lets you continue in spite of errors and handle them. It won't magically fix your errors.

  2. Importing text file : No Columns to parse from file

    To Solve Importing text file : No Columns to parse from file Error Using try and except just lets you continue in spite of errors and handle them. It won't magically fix your errors.

Solution 1

Using try and except just lets you continue in spite of errors and handle them. It won’t magically fix your errors.

read_csv expects csv files, which your input is obviously not. A quick look into the documentation:

delim_whitespace : boolean, default False

Specifies whether or not whitespace (e.g. ‘ ‘ or ‘ ‘) will be used as the sep. Equivalent to setting sep=’+s’. If this option is set to True, nothing should be passed in for the delimiter parameter.

This seems like the right argument. Use

pandas.read_csv(filepath_or_buffer, delim_whitespace=True).

Using delimiter='\t' should also work, unless the tabs are expanded (replaced by spaces). As we can’t really tell, delim_whitespace seems to be the better option.

If this doesn’t help, just print out your sys.stdin to check if you properly pass the text.

Edit: I just saw that you use

cat /root/lab/u.data | python /root/lab/mid-1-mapper.py |python /root/lab/mid-1-reducer.py

Is this intended, this way mid-1-reducer.py processes the output of mid-1-mapper.py. If you want to process the content of the file u.data consider reading the file and not sys.stdin.

Solution 2

You have to set delim_whitespace to True, to use whitespaces as the separator.

import sys
import pandas as pd

if __name__ == '__main__':
    df = pd.read_csv(sys.stdin, header=None, delim_whitespace=True)
    print df

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read