繁体   English   中英

在jupyter笔记本中执行多行

[英]execute multiple lines in jupyter notebook

我是python和jupyter笔记本的新手。

搜索后,我发现如果要对sqlContext执行多行,则必须使用三元组“””,如下所示:

sqlContext.sql("""select year,month,count(distinct station) as count
               from tempReadingsTable
               where year>=1950 and year<=2014 and value>=10
               group by year,month
               order by count desc
                """).show()

现在,我试图为此找到相同的内容:

schMax = schMax.groupBy('year').
agg(fun.max('value').alias('value')).
join(sch['year','value']).
drop_duplicates(['year']).
select(['year','station','value']).
orderBy(['value'],ascending=[0])

除非我全部运行一行,否则它将失败! 我该如何预防呢? 我希望能够分别执行所有行...

您可以在一行的末尾使用\\来让python继续读取下一行作为上一行的一部分(如果需要,请删除空格)。 尽管我认为如果将放进去,则可读性更高. 在每个新行的开头。 显然,它是上一条语句的一部分,因为普通语句从不以开头. 在python中。

 schMax = schMax.groupBy('year')\
                .agg(fun.max('value').alias('value'))\
                .join(sch['year','value'])\
                .drop_duplicates(['year'])\
                .select(['year','station','value'])\
                .orderBy(['value'],ascending=[0])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM