databricks_如何開始使用Databricks

databricks

by Shubhi Asthana

通過Shubhi Asthana

如何開始使用Databricks (How to get started with Databricks)

When I started learning Spark with Pyspark, I came across the Databricks platform and explored it. This platform made it easy to setup an environment to run Spark dataframes and practice coding. This post contains some steps that can help you get started with Databricks.

當我開始使用Pyspark學習Spark時,我遇到了Databricks平臺并進行了探索。 通過該平臺,可以輕松設置運行Spark數據幀和練習編碼的環境。 這篇文章包含一些步驟,可以幫助您開始使用Databricks。

Databricks is a platform that runs on top of Apache Spark. It conveniently has a Notebook systems setup. One can easily provision clusters in the cloud, and it also incorporates an integrated workspace for exploration and visualization.

Databricks是一個在Apache Spark之上運行的平臺。 它方便地具有筆記本電腦系統設置。 可以輕松地在云中配置群集,并且它還集成了用于探索和可視化的集成工作區。

You can also schedule any existing notebook or locally developed Spark code to go from prototype to production without re-engineering.

您還可以計劃任何現有的筆記本電腦或本地開發的Spark代碼,從原型制作到生產,而無需重新設計。

1. 設置一個Databricks帳戶 (1. Setup a Databricks account)

To get started with the tutorial, navigate to this link and select the free Community Edition to open your account. This option has single cluster with up to 6 GB free storage. It allows you to create a basic Notebook. You’ll need a valid email address to verify your account.

要開始使用本教程,請導航至此鏈接,然后選擇免費的Community Edition打開您的帳戶。 此選項具有最多6 GB可用存儲的單個群集。 它允許您創建一個基本的Notebook。 您需要一個有效的電子郵件地址來驗證您的帳戶。

You will observe this screen once you successfully log in to your account.

成功登錄帳戶后,您將看到此屏幕。

2. 創建一個新集群 (2. Creating a new Cluster)

We start with creating a new cluster to run our programs on. Click on “Cluster” on the main page and type in a new name for the cluster.

我們首先創建一個新的集群來運行我們的程序。 單擊主頁上的“群集”,然后為群集鍵入一個新名稱。

Next, you need to select the “Databricks Runtime” version. Databricks Runtime is a set of core components that run on clusters managed by Databricks. It includes Apache Spark, but also adds a number of components and updates to improve the usability and performance of the tool.

接下來,您需要選擇“ Databricks Runtime”版本。 Databricks Runtime是一組在Databricks管理的群集上運行的核心組件。 它包括Apache Spark,但還添加了許多組件和更新以改善該工具的可用性和性能。

You can select any Databricks Runtime version — I have selected 3.5 LTS (includes Apache Spark 2.2.1, Scala 2.11). You also have a choice between Python 2 and 3.

您可以選擇任何Databricks Runtime版本-我選擇了3.5 LTS(包括Apache Spark 2.2.1,Scala 2.11)。 您還可以在Python 2和3之間進行選擇。

It’ll take a few minutes to create the cluster. After some time, you should be able to see an active cluster on the dashboard.

創建集群需要幾分鐘。 一段時間后,您應該能夠在儀表板上看到活動的集群。

3. 創建一個新的筆記本 (3. Creating a new Notebook)

Let’s go ahead and create a new Notebook on which you can run your program.

讓我們繼續創建一個新的Notebook,您可以在其上運行程序。

From the main page, hit “New Notebook” and type in a name for the Notebook. Select the language of your choice — I chose Python here. You can see that Databricks supports multiple languages including Scala, R and SQL.

在主頁上,單擊“新筆記本”,然后輸入筆記本的名稱。 選擇您選擇的語言-我在這里選擇了Python。 您可以看到Databricks支持多種語言,包括Scala,R和SQL。

Once the details are entered, you will observe that the layout of the notebook is very similar to the Jupyter notebook. To test the notebook, let’s import pyspark.

輸入詳細信息后,您會發現筆記本的布局與Jupyter筆記本非常相似。 要測試筆記本,讓我們導入pyspark。

The command ran in 0.15 seconds and also gives the cluster name on which it is running. If there are any errors in the code, it would show below the cmd box.

該命令運行了0.15秒,并且還給出了運行命令的集群名稱。 如果代碼中有任何錯誤,它將顯示在cmd框下方。

You can hit the keyboard icon on the top right corner of the page to see operating system-specific shortcuts.

您可以點擊頁面右上角的鍵盤圖標來查看特定于操作系統的快捷方式。

The most important shortcuts here are:

這里最重要的快捷方式是:

  • Shift+Enter to run a cell

    Shift + Enter鍵運行單元格
  • Ctrl+Enter keeps running the same cell without moving to the next cell

    Ctrl + Enter保持運行相同的單元格,而無需移動到下一個單元格

Note these shortcuts are for Windows. You can check the OS-specific shortcuts for your OS on the keyboard icon.

請注意,這些快捷方式適用于Windows。 您可以在鍵盤圖標上檢查操作系統特定于操作系統的快捷方式。

4. 將數據上傳到Databricks (4. Uploading data to Databricks)

Head over to the “Tables” section on the left bar, and hit “Create Table.” You can upload a file, or connect to a Spark data source or some other database.

轉到左側欄上的“表格”部分,然后點擊“創建表格”。 您可以上傳文件,或連接到Spark數據源或其他數據庫。

Let’s upload the commonly used iris dataset file here (if you don’t have the dataset, use this link )

讓我們在這里上傳常用的虹膜數據集文件(如果您沒有數據集,請使用此鏈接 )

Once you upload the data, create the table with a UI so you can visualize the table, and preview it on your cluster. As you can see, you can observe the attributes of the table. Spark will try to detect the datatype of each of the columns, and lets you edit it too.

上載數據后,使用UI創建表,以便可以可視化表并在集群上預覽。 如您所見,您可以觀察表的屬性。 Spark將嘗試檢測每列的數據類型,并讓您對其進行編輯。

Now I need to put headers for the columns, so I can identify each column by their header instead of _c0, _c1 and so on.

現在,我需要為各列添加標題,以便可以通過其標題而不是_c0_c1等等來標識每一列。

I put their headers as Sepal Length, Sepal Width, Petal Length, Petal Width and Class. Here, Spark detected the datatype of the first four columns incorrectly as a String, so I changed it to the desired datatype — Float.

我把它們的標題設置為“分隔長度”,“分隔寬度”,“花瓣長度”,“花瓣寬度”和“類”。 在這里,Spark錯誤地將前四列的數據類型檢測為String,因此我將其更改為所需的數據類型-Float。

5. 如何從筆記本電腦訪問數據 (5. How to access data from Notebook)

Spark is a framework that can be used to analyze big data using SQL, machine learning, graph processing or real-time streaming analysis. We will be working with SparkSQL and Dataframes in this tutorial.

Spark是一個框架,可用于使用SQL,機器學習,圖形處理或實時流分析來分析大數據。 在本教程中,我們將使用SparkSQL和Dataframes。

Let’s get started with working with the data on the Notebook. The data that we have uploaded is now put in tabular format.We require a SQL query to read the data and put it in a dataframe.

讓我們開始使用筆記本上的數據。 現在,我們已上傳的數據以表格格式放置。我們需要一個SQL查詢來讀取數據并將其放置在數據框中。

Type df = sqlContext.sql(“SELECT * FROM iris_data”) to read iris data into a dataframe.

類型df = sqlContext.sql(“SELECT * FROM iris_data”) 將虹膜數據讀入數據幀。

To view the first five rows in the dataframe, I can simply run the command:

要查看數據框中的前五行,我可以簡單地運行以下命令:

display(df.limit(5))

display(df.limit(5))

Notice a Bar chart icon at the bottom. Once you click, you can view the data that you have imported into Databricks. To view the bar chart of complete data, rundisplay(df) instead of display(df.limit(5)).

注意底部的條形圖圖標。 單擊后,您可以查看已導入到Databricks中的數據。 要查看完整數據的條形圖,請運行display(df)而不是display(df.limit(5))

The dropdown button allows you to visualize the data in different charts like bar, pie, scatter, and so on. It also gives you plot options to customize the plot and visualize specific columns only.

下拉按鈕使您可以可視化不同圖表中的數據,如條形圖,餅圖,散點圖等。 它還提供了繪圖選項,以自定義繪圖并僅顯示特定的列。

You can also display matplotlib and ggplot figures in Databricks. For a demonstration, see Matplotlib and ggplot in Python Notebooks.

您還可以在Databricks中顯示matplotlib和ggplot數字。 有關演示,請參閱Python Notebooks中的Matplotlib和ggplot 。

To view all the columns of the data, simply type df.columns

要查看數據的所有列,只需鍵入df.columns

To count how many rows total there are in the Dataframe (and see how long it takes to a full scan from remote disk/S3), run df.count().

要計算數據幀中總共有多少行(并查看從遠程磁盤/ S3進行全面掃描所花費的時間),請運行df.count()

6.將Spark數據框轉換為Pandas數據框。 (6. Converting a Spark dataframe to a Pandas dataframe.)

Now if you are comfortable using pandas dataframes, and want to convert your Spark dataframe to pandas, you can do this by putting the command

現在,如果您習慣使用pandas數據框,并且想要將Spark數據框轉換為pandas,則可以通過以下命令來完成此操作

import pandas as pdpandas_df=df.to_pandas()

Now you can use pandas operations on the pandas_df dataframe.

現在,您可以在pandas_df數據幀上使用pandas操作。

7.查看Spark UI (7. Viewing the Spark UI)

The Spark UI contains a wealth of information needed for debugging Spark jobs. There are a bunch of great visualizations, so let’s view them in a gist.

Spark UI包含調試Spark作業所需的大量信息。 有很多很棒的可視化效果,所以讓我們大致了解一下它們。

To go to Spark UI, you need to go to the top of the page where there are some menu options like “File,” “View,” “Code,” “Permissions,” and others. You will find the name of the cluster at the top next to “Attached” and a dropdown button next to it. Hit the dropdown button and select “View Spark UI.” A new tab will open up with the lots of information on your Notebook.

要轉到Spark UI,您需要轉到頁面頂部,這里有一些菜單選項,如“文件”,“視圖”,“代碼”,“權限”等。 您將在“已附加”旁邊的頂部找到集群的名稱,并在其旁邊找到一個下拉按鈕。 點擊下拉按鈕,然后選擇“查看Spark UI”。 一個新的選項卡將打開,其中包含筆記本電腦上的大量信息。

The UI view gives plenty of information on each job executed on the cluster, stages, environment, and SQL queries executed. This UI can be helpful for users to debug their applications. Also, this UI gives a good visualization on Spark streaming statistics. To learn in more detail about each aspect of the Spark UI, refer to this link.

UI視圖提供了有關在集群上執行的每個作業,階段,環境和執行SQL查詢的大量信息。 該UI有助于用戶調試其應用程序。 此外,此UI還提供了關于Spark流統計的良好可視化效果。 要詳細了解Spark UI的各個方面,請參閱此鏈接 。

Once you are done with the Notebook, you can go ahead and publish it or export the file in different file formats, such that somebody else can use it using a unique link. I have attached my Notebook in HTML format.

使用筆記本電腦完成操作后,您可以繼續發布并以不同的文件格式導出文件,以便其他人可以通過唯一鏈接使用它。 我已經以HTML格式附加了我的筆記本 。

結語 (Wrapping up)

This is a short overview on how you can get started with Databricks quickly and run your programs. The advantage of using Databricks is that it offers an end-to-end service for building analytics, data warehousing, and machine learning applications. The entire Spark cluster can be managed, monitored, and secured using a self-service model of Databricks.

這是有關如何快速開始使用Databricks并運行程序的簡短概述。 使用Databricks的優勢在于,它為構建分析,數據倉庫和機器學習應用程序提供了端到端服務。 可以使用Databricks的自助模型來管理,監視和保護整個Spark集群。

Here are some interesting links for Data Scientists and for Data Engineers. Also, here is a tutorial which I found very useful and is great for beginners.

這是數據科學家和數據工程師的一些有趣鏈接。 另外,這是我發現非常有用的教程 ,對初學者來說非常有用。

翻譯自: https://www.freecodecamp.org/news/how-to-get-started-with-databricks-bc8da4ffbccb/

databricks

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/394378.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/394378.shtml
英文地址,請注明出處:http://en.pswp.cn/news/394378.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

簡述isodata算法的原理_算法常見面試題匯總(一):概率論與數理統計部分

初級或中級算法崗面試題主要有四類:數理統計基礎、機器學習模型原理、編程能力、項目經驗。項目經驗因人而異,所以僅總結前三個方面的基礎知識,分享給朋友。(高級或資深算法崗面試內容不在本文范圍內)1.大數定律弱大數…

shell中各種括號的作用()、(())、[]、[[]]、{}

轉自:http://blog.csdn.net/taiyang1987912/article/details/39551385 一、小括號,圓括號() 1、單小括號 () ①命令組。括號中的命令將會新開一個子shell順序執行,所以括號中的變量不能夠被腳本余下的部分使用。括號中…

SQLite 數據類型

SQLite 數據類型 參考: SQLite 數據類型 | 菜鳥教程http://www.runoob.com/sqlite/sqlite-data-types.html SQLite 數據類型是一個用來指定任何對象的數據類型的屬性。SQLite 中的每一列,每個變量和表達式都有相關的數據類型。 您可以在創建表的同時使用…

leetcode1143. 最長公共子序列(動態規劃)

給定兩個字符串 text1 和 text2,返回這兩個字符串的最長公共子序列的長度。 一個字符串的 子序列 是指這樣一個新的字符串:它是由原字符串在不改變字符的相對順序的情況下刪除某些字符(也可以不刪除任何字符)后組成的新字符串。 …

php開發支付寶支付密碼忘記了怎么辦_密碼箱忘記密碼怎么辦?密碼箱解鎖方法大全...

密碼箱忘記密碼經常發生,有時候急著趕車趕飛機必須用的證件在密碼行李箱,怎么辦?破壞?當你忘記密碼的時候千萬不要著急,不要試著用暴力破壞密碼鎖。操作方法一此類型的密碼箱的開鎖方法。把箱子放在光線好的地方放平&a…

Python網絡編程之TCP服務器客戶端(二)

傳輸控制協議(官方術語為TCP/IP協議)是互聯網的重要組成部分。TCP的第一個版本是在1974年定義的,它建立在網際層協議(IP)提供的數據包傳輸技術之上。TCP使得應用程序可以使用連續的數據流進行相互通信,除非出現網絡原因導致連接中斷等意外情況&#xff0…

請寫出至少5個html塊元素標簽_34道常見的HTML+CSS面試題(附答案)

公眾號【傳智播客博學谷】回復關鍵詞:前端 PS Java(100G) Python(80G) 大數據 區塊鏈 測試 PPT JS(40g300教程) HTML 簡歷 領取相關學習資料!一、HTML1、標簽上title屬性與alt屬性的區別是什么?alt屬性是為了給那些不能看到你文檔中圖像的瀏覽…

leetcode劍指 Offer 42. 連續子數組的最大和(動態規劃)

輸入一個整型數組,數組里有正數也有負數。數組中的一個或連續多個整數組成一個子數組。求所有子數組的和的最大值。 要求時間復雜度為O(n)。 示例1: 輸入: nums [-2,1,-3,4,-1,2,1,-5,4] 輸出: 6 解釋: 連續子數組 [4,-1,2,1] 的和最大,為 6。 常數…

nginx mozilla_我發現Mozilla的私人瀏覽模式存在重大缺陷。

nginx mozillaby Konark Modi通過Konark Modi 我發現Mozilla的私人瀏覽模式存在重大缺陷。 (I found a major flaw in Mozilla’s private browsing mode.) If left unfixed this flaw could have wreaked havoc but Mozilla’s prompt fixes saved the day.如果不加以解決&am…

4月8日隨筆

周一滿課,晚上唱紅歌,寫概率論。。 轉載于:https://www.cnblogs.com/wxy2000/p/10686058.html

linux開機出現一下錯誤Give root password for maintenance (or type Control-D to continue):

linux開機出現一下錯誤Give root password for maintenance (or type Control-D to continue):第一種錯誤的情況:由于錯誤的編輯/etc/fstab文件 而引起的不能正常進入系統。假如你將某一個分區或者磁盤最后一個參數設置為1或2時,系統默認會在開機過程中檢…

[閱讀筆記]Zhang Y. 3D Information Extraction Based on GPU.2010.

1.立體視覺基礎 深度定義為物體間的距離 視差定義為同一點在左圖(reference image) 和右圖( target image) 中的x坐標差。 根據左圖中每個點的視差得到的灰度圖稱為視差圖。 那么根據三角幾何關系可以由視差(xR - xT ) 計算出深度.bcamera基線距離,f焦距。 離相機越…

r語言 小樹轉化百分數_“小樹”機器人1.0新品發布會

產品初衷伴隨著AI的落地,從最開始的刷臉支付,再到自動駕駛,還是現在互聯網的5G時代,AI無疑都是產業變革的核心動力。那么作為一家科技創新的企業,小樹機器人從建立之初就在不斷的創新,我們致力于從智能出發…

mac安裝python虛擬環境_詳解Mac配置虛擬環境Virtualenv,安裝Python科學計算包

最近正在自學Python做科學計算,當然在很多書籍和公開課里最先做的就是安裝Numpy, Scipy, Matplotlib等包,不過每次安裝單獨的包時,都會有各種問題導致安裝失敗或者調用失敗。比如,遇到 Exception 和 Error:明明已經提示…

破解系統設計訪談:Twitter軟件工程師的提示

by Zhia Hwa Chong志華化 破解系統設計訪談:Twitter軟件工程師的提示 (Crack the System Design interview: tips from a Twitter software engineer) I recently wrote about how I landed offers from multiple top-tier tech companies. During my interview pr…

leetcode474. 一和零(動態規劃)

在計算機界中,我們總是追求用有限的資源獲取最大的收益。 現在,假設你分別支配著 m 個 0 和 n 個 1。另外,還有一個僅包含 0 和 1 字符串的數組。 你的任務是使用給定的 m 個 0 和 n 個 1 ,找到能拼出存在于數組中的字符串的最大…

jQuery對象與DOM對象的相互轉換

一、檢測方式上的區別 檢測DOM對象: if (Object.nodeType) 檢測jQery對象: if (Object.jquery) 二、轉換方式 jQuery對象轉DOM對象: var DOMObject jQueryObject.get([index]); // 或者 var DOMObject jQueryObject[index]; DOM對象轉jQuer…

ProcessExplore 最新版

http://files.cnblogs.com/files/zhangdongsheng/ProcessExplorer.zip轉載于:https://www.cnblogs.com/zhangdongsheng/p/6195743.html

javascript對象包含哪些要素_讓人迷糊的JavaScript對象(Object一)

對于很多初學的小伙伴聽到JavaScript內置對象、BOM、DOM、WEB API等關鍵詞基本上都是迷糊,不是很明白他們之間的關系,以及他們是如果建立聯系的。雖然我們現在小伙伴在學VUE,React等框架能簡化我們的操作,但是遇到一些基礎的問題還…

被吐嘈的NodeJS的異常處理

被吐嘈的NodeJS的異常處理 許多人都有這樣一種映像,NodeJS比較快; 但是因為其是單線程,所以它不穩定,有點不安全,不適合處理復雜業務; 它比較適合對并發要求比較高,而且簡單的業務場景。 在Expr…