pandasql: 如何 select 非英文命名列?
pandasql: How to select non english named column?
Dataframe 有非英文命名的列,如何select 这样的列?
import pandasql as pdsql
pysql = lambda q: pdsql.sqldf(q, globals())
sqlquery = 'select ''Машина'', min(''Дата доставки'') from days_ans group by 1'
pysql(sqlquery)
最后一行 returns 一个错误:
PandaSQLException: (sqlite3.OperationalError) near "доставки": syntax error [SQL: 'select Машина, min(Дата доставки) from days_ans group by 1']
PS 未指定列 - 正常工作:
sqlquery = 'select * from days_ans limit 1'
sqlquery = 'select ''Партнер'' from days_ans limit 1'
我认为问题与其中包含空格的列有关
你的单引号 ''
连接起来就什么都没有了。尝试在字符串的两边使用双引号:
>>> sqlquery = 'select ''Машина'', min(''Дата доставки'') from days_ans group by 1'
>>> sqlquery
'select Машина, min(Дата доставки) from days_ans group by 1'
>>> sqlquery = "select ''Машина'', min(''Дата доставки'') from days_ans group by 1"
>>> sqlquery
"select ''Машина'', min(''Дата доставки'') from days_ans group by 1"
Dataframe 有非英文命名的列,如何select 这样的列?
import pandasql as pdsql
pysql = lambda q: pdsql.sqldf(q, globals())
sqlquery = 'select ''Машина'', min(''Дата доставки'') from days_ans group by 1'
pysql(sqlquery)
最后一行 returns 一个错误:
PandaSQLException: (sqlite3.OperationalError) near "доставки": syntax error [SQL: 'select Машина, min(Дата доставки) from days_ans group by 1']
PS 未指定列 - 正常工作:
sqlquery = 'select * from days_ans limit 1'
sqlquery = 'select ''Партнер'' from days_ans limit 1'
我认为问题与其中包含空格的列有关
你的单引号 ''
连接起来就什么都没有了。尝试在字符串的两边使用双引号:
>>> sqlquery = 'select ''Машина'', min(''Дата доставки'') from days_ans group by 1'
>>> sqlquery
'select Машина, min(Дата доставки) from days_ans group by 1'
>>> sqlquery = "select ''Машина'', min(''Дата доставки'') from days_ans group by 1"
>>> sqlquery
"select ''Машина'', min(''Дата доставки'') from days_ans group by 1"