0

Python 3.4 using Pandas in beginners tutorial. Code below. Keep getting syntax error in print with carrot under the d in pd. Spent last hour trolling the web to no avail. Just starting out.

import numpy as np
import csv as csv
import pandas as pd
readdata = csv.reader(open("c:\MyData\BYLCsv.csv"))
data = []

for row in readdata:
    data.append(row)

Header = data[0]
data.pop(0)
print pd.DataFrame(data, columns=Header)
Ismael Padilla
  • 5,246
  • 4
  • 23
  • 35
jpl458
  • 595
  • 3
  • 9
  • 17
  • 1
    See related: http://stackoverflow.com/questions/826948/syntax-error-on-print-with-python-3 – EdChum Mar 01 '15 at 17:45
  • I find it helps to google for keywords. For example, "python print syntax error". – DSM Mar 01 '15 at 17:45
  • 3
    basically python 3 print is a function so you have to wrap your args in parentheses so do this `print(pd.DataFrame(data, columns=Header))` – EdChum Mar 01 '15 at 17:45
  • And apart from the print error, you can also use `pd.read_csv` instead of looping over the csv file rows yourself. – joris Mar 01 '15 at 18:25

1 Answers1

3

You are probably using python 3 and for the print command you need the parenthesis:

print (pd.DataFrame(data, columns=Header))
Paul Roub
  • 36,322
  • 27
  • 84
  • 93