top of page

Python Script Error - Wrong Number of Columns Error Because of Hash Sign

The Python programming language can be used to parse through text that is too large for Excel to handle. See an excellent demonstration on the Sentdex YouTube channel on how to use Python in conjunction with the NumPy extension to pull data from Excel files: . [If you have trouble loading the Numpy file, see the instructions at, . It is currently available at , see numpy‑1.10.0b1+mkl‑cp27‑none‑win_amd64.whl, for a 64 bit Windows system. ] If the text in a .csv file has hash signs (#) you may find errors in the results that a Python script collects, or you may find a persistent error about the Python script not listing the number of columns correctly.

In this video posted to my YouTube channel, you can see how the hash sign in the second to last column, causes Python to return the error message, "Wrong number of columns at line 2".

Python uses hash signs to identify comments. When the script is modified to include the command comments=None the error will no longer occur.

Also note that unless this change is made, the presence of hash symbols in the last column will prevent Python from collecting the full entry in the last column - it will only return the entry up to and including the hash symbol.

bottom of page