I'm trying to run the following code in Google Colab but I'm receving the error 'EOF in multi-line string'
import sqlite3
from google.colab import files
uploaded = files.upload()
#upload file Db-IMDB.db
connection = sqlite3.connect('./Db-IMDB.db')
Yash = pd.read_sql_query("""SELECT da.*
FROM (SELECT pd.pid, pd.name as Director, pa.pid, pa.name as actor, COUNT(*) as cnt,
RANK() OVER (PARTITION BY pa.pid ORDER BY COUNT(*) DESC) as seqnum,
COUNT(*) OVER (PARTITION BY pa.pid, COUNT(*)) as num_with_cnt,
FROM M_director d JOIN
Person pd
ON pd.pid = d.pid JOIN
M_cast c
ON c.MID = d.MID JOIN
Person pa
ON pa.PID = c.PID
GROUP BY pd.pid, pd.name, pa.pid, pa.name
) da
WHERE director = 'Yash Chopra' AND
seqnum = 1 AND
num_with_cnt = 1;""",connection)
print(Yash)
I've gone through queries posted by other users on this error, from what I've seen it is always due to a missing apostraphie '
however, I've checked my code and I didn't miss any. Can you please help me figure out what is causing the error ?
My references : Token error: EOF in multi-line statement Getting error when loading CSV file to dataframe using Jupyter notebook
Complete error :
ERROR:root:An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line string', (1, 23))
---------------------------------------------------------------------------
OperationalError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/pandas/io/sql.py in execute(self, *args, **kwargs)
1430 else:
-> 1431 cur.execute(*args)
1432 return cur
OperationalError: near "(": syntax error
During handling of the above exception, another exception occurred:
DatabaseError Traceback (most recent call last)
5 frames
/usr/local/lib/python3.6/dist-packages/pandas/io/sql.py in execute(self, *args, **kwargs)
1429 cur.execute(*args, **kwargs)
1430 else:
-> 1431 cur.execute(*args)
1432 return cur
1433 except Exception as exc:
DatabaseError: Execution failed on sql 'SELECT da.*
FROM (SELECT pd.pid, pd.name as Director, pa.pid, pa.name as actor, COUNT(*) as cnt,
RANK() OVER (PARTITION BY pa.pid ORDER BY COUNT(*) DESC) as seqnum,
COUNT(*) OVER (PARTITION BY pa.pid, COUNT(*)) as num_with_cnt,
FROM M_director d JOIN
Person pd
ON pd.pid = d.pid JOIN
M_cast c
ON c.MID = d.MID JOIN
Person pa
ON pa.PID = c.PID
GROUP BY pd.pid, pd.name, pa.pid, pa.name
) da
WHERE director = 'Yash Chopra' AND
seqnum = 1 AND
num_with_cnt = 1;': near "(": syntax error