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: https://www.youtube.com/watch?v=pbjGo3oj0PM . [If you have trouble loading the Numpy file, see the instructions at, https://www.youtube.com/watch?v=IHRQ5NBqiy8 . It is currently available at http://www.lfd.uci.edu/~gohlke/pythonlibs/ , 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.


 

Sean O'Shea has more than 20 years of experience in the litigation support field with major law firms in New York and San Francisco.   He is an ACEDS Certified eDiscovery Specialist and a Relativity Certified Administrator.

​

The views expressed in this blog are those of the owner and do not reflect the views or opinions of the owner’s employer.

​

If you have a question or comment about this blog, please make a submission using the form to the right. 

Your details were sent successfully!

© 2015 by Sean O'Shea . Proudly created with Wix.com

bottom of page