我对 PandaSQL 很陌生,以前从未使用过它。到目前为止,这是我的代码:
import pandas as pd
from pandasql import sqldf
import numpy as np
tasks = pd.read_csv("C:/Users/RMahesh/Documents/TASKS_Final_2.csv", encoding='cp1252')
query = """SELECT Work Item Id, Parent Work Item Id, MAX(Remaining Work)
FROM TASKS
GROUP BY Work Item Id, Parent Work Item Id;"""
df = sqldf(query, locals()))
print(df.head(5))
我收到此错误:
'pandasql.sqldf.PandaSQLException: (sqlite3.OperationalError) near "Id": syntax error [SQL: 'SELECT Work Item Id, Parent Work Item Id, MAX(Remaining Work) \n'
任何帮助都会很棒!
编辑:在执行以下其他用户的一些建议后,这是我的工作代码:
import pandas as pd
from pandasql import sqldf
import numpy as np
tasks = pd.read_csv("C:/Users/RMahesh/Documents/TASKS_Final_2.csv", encoding='cp1252', low_memory=False)
query = """SELECT [Work Item Id], [Parent Work Item Id], MAX([Remaining Work])
FROM tasks
GROUP BY [Work Item Id], [Parent Work Item Id];"""
print(sqldf(query, locals()))