0

I am running a script with Python 2.7 using pandas to read from 2 csv files. I keep getting "invalid syntax" error messages, particularly on line 6 and 8. I can't figure out where is the problem, since line 6 is almost identical to line 5 and there I don't get any error. Thanks very much for your help !

import numpy as np
import csv as csv
import pandas as pd

da = pd.read_csv('snp_rs.csv', index_col=(0,1), usecols=(0, 1), header=None,    converters = dict.fromkeys([0,1])
db = pd.read_csv('chl.map.csv', index_col=(0,1), usecols=(0,1), header=None,    converters = dict.fromkeys([0,1])

result = da.join(db, how='inner')
x = result.to_csv('snp_rs_out.csv', header=None) # write as csv
print x
5
  • 6
    close the () in pd.read Commented Oct 22, 2015 at 13:57
  • @VigneshKalai should be an answer. Commented Oct 22, 2015 at 14:02
  • 1
    I'm flagging this post as off-topic since it's a simple typographical error. I wonder how this could get 3 upvotes. Commented Oct 22, 2015 at 14:09
  • Thanks very much guys !. I am sorry that Mr Massias got upset. I have been programming for only 1 month... Commented Oct 22, 2015 at 17:23
  • The confusing thing is that the error is actually in the previous line. Python doesn't detect the missing ) until it starts to process the next line. It's ok to ask about typographical errors. We make those all the time. Commented Oct 22, 2015 at 17:26

1 Answer 1

2

As commented you need to close the parentheses around you read_csv call:

da = pd.read_csv('snp_rs.csv', index_col=(0,1), usecols=(0, 1), header=None,    converters = dict.fromkeys([0,1])

It's missing a closing paren.

I find it a lot easier to write/read these if you split the lines:

da = pd.read_csv('snp_rs.csv',
                 index_col=(0,1),
                 usecols=(0, 1),
                 header=None,
                 converters=dict.fromkeys([0,1])

then it's much clearer that a final ) is missing.

Sign up to request clarification or add additional context in comments.

3 Comments

sometimes answers for simple typo like this may lead to down votes so did not answer :)
@VigneshKalai very true. Sometimes I like to live dangerously. :p
After having 62k and python gold badge you can live dangerously :P

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.