I need to read in the file https://drive.google.com/open?id=0B29hT1HI-pwxMjBPQWFYaWoyalE) however, I have tried 3-4 different code methods and repeatedly get the error: "line contains NULL byte". I read on other threads that this is a problem with your csv-but, this is the file that my professor will be loading and grading me on, and I can't modify it, so I'm looking for a solution around this error.
As I mentioned I've tried several different methods to open the file. Here's my best two:
def largestState():
INPUT = "statepopulations.csv"
COLUMN = 5 # 6th column
with open(INPUT, "rU") as csvFile:
theFile = csv.reader(csvFile)
header = next(theFile, None) # skip header row
pop = [float(row[COLUMN]) for row in theFile]
max_pop = max(pop)
print max_pop
largestState()
This results in the NULL Byte error. Please ignore the additional max_pop lines. The next step after reading the file in is to find the maximum value of row F.
def test():
with open('state-populations.csv', 'rb') as f:
reader = csv.reader(f)
for row in reader:
print row
test()
This results in the NULL Byte Error.
If anyone could offer a simple solution to this problem I'd greatly appreciate it.
File as .txt: https://drive.google.com/open?id=0B29hT1HI-pwxZzhlMGZGVVAzX28