pyspark在ipython notebook

时间:2017-04-15 14:17:54

标签: pandas pyspark ipython jupyter-notebook pyspark-sql

pyspark.sql.DataFrame显示凌乱的DataFrame.show() - 换行而不是滚动。

enter image description here

但显示pandas.DataFrame.head enter image description here

我尝试了这些选项

import IPython
IPython.auto_scroll_threshold = 9999

from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
from IPython.display import display

但没有运气。虽然在Atom编辑器中使用jupyter插件时滚动工作:

enter image description here

7 个答案:

答案 0 :(得分:11)

这是一种解决方法

@NgModule({
  declarations: [
    //declaration
  ],
  imports: [
    //other modules 
    ComponentsModule,
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    //ionic pages
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler},
    //other providers
  ]
})
export class AppModule {}

尽管,我不知道此查询的计算负担。我认为spark_df.limit(5).toPandas().head() 并不昂贵。更正。

答案 1 :(得分:8)

只需编辑css文件,一切就好了。

  1. 打开jupyter笔记本../site-packages/notebook/static/style/style.min.css文件。

  2. 搜索white-space: pre-wrap;,然后将其删除。

  3. 保存文件并重新启动jupyter-notebook。

问题已解决。 :)

答案 2 :(得分:1)

除了上述@ karan-singla和@ vijay-jangir给出的答案之外,可以方便地用单线注释掉white-space: pre-wrap样式的方式如下:

$ awk -i inplace '/pre-wrap/ {$0="/*"$0"*/"}1' $(dirname `python -c "import notebook as nb;print(nb.__file__)"`)/static/style/style.min.css

这翻译为;使用awk更新包含pre-wrap inplace 行,将其用*/ -- */包围,即注释掉您在styles.css中找到的文件工作的Python环境。

从理论上讲,如果人们使用多个环境(例如Anaconda),则可以将其用作别名。

参考:

答案 3 :(得分:0)

我不确定是否仍然有人在面对这个问题。但这可以通过使用开发人员工具调整某些网站设置来解决。

您为什么enter image description here

打开开发人员设置( F12 )。然后检查元素( ctrl + shift + c ) 然后单击输出。并取消选中空格属性(请参见下面的快照) enter image description here

您只需要执行一次此操作即可。 (除非刷新页面)

这将直接向您显示确切的数据。无需转换为熊猫。

答案 4 :(得分:0)

尝试display(dataframe_name),它呈现可滚动的表格。

答案 5 :(得分:0)

准确来说是之前有人说过的话。 在文件 YES 有 2 anaconda3/lib/python3.7/site- packages/notebook/static/style/style.min.css 你必须以这种方式在这里评论一个 white-space: nowrap; 保存并重启jupyter

答案 6 :(得分:-1)

我在li' l函数下创建了它并且工作正常:

def printDf(sprkDF): 
    newdf = sprkDF.toPandas()
    from IPython.display import display, HTML
    return HTML(newdf.to_html())

如果您愿意,可以直接在火花查询中使用它,或者在任何火花数据框上使用它:

printDf(spark.sql('''
select * from employee
'''))