美文网首页
python中使用pandasql包

python中使用pandasql包

作者: 485b1aca799e | 来源:发表于2017-06-18 11:13 被阅读0次
  • 对于很多数据分析的新手而言,学习pandas包和numpy包需要一段时间的努力,此时pandasql包提供了使用sql语句来对于数据框的处理,类似与R语言中的sqldf包

  • 加载pandasql包后,直接在sqldf函数中写sql代码即可,和R中sqldf包不同的是,需要加一个globals()的全局变量参数,pandasql包将一个DataFrame对象转变为DataFrame对象。

from pandasql import sqldf

x0=sqldf('select * from x where date in ("2017-05-15") order by date,hour limit 3',globals())
x1=sqldf('select * from x  where date in ("2017-05-15")',globals())
x2=sqldf('select * from x  where date in ("2017-05-16")',globals())
sqldf('select count(distinct hour ) from (select * from x1 union all  select *   from x2) ',globals())


相关文章

网友评论

      本文标题:python中使用pandasql包

      本文链接:https://www.haomeiwen.com/subject/vfyiqxtx.html