3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

GAされたDatabricks Workspace Filesを試してみる

Last updated at Posted at 2023-04-25

こちらの機能を試してみます。

Pythonモジュールの作成

これまではRepos配下でしか.pyファイルを作成できませんでしたが、ワークスペースのどこでもファイルを作成できます。これだけでも相当便利。
Screenshot 2023-04-25 at 14.22.02.png
Screenshot 2023-04-25 at 14.22.24.png

mymodule.py
def funcname():
       print(__name__)

ノートブックを作成して、モジュールをインポートします。

notebook
import mymodule
mymodule.funcname()
mymodule

カスタムPythonライブラリの開発が捗ります。

データの格納

DBFSを気にすることなしに、ノートブックと同じ場所に手軽にファイルをアップロードできます。
Screenshot 2023-04-25 at 14.17.42.png

Python
import pandas as pd

df = pd.read_csv("/Workspace/Users/takaaki.yayoi@databricks.com/20230425_workspace_files/japan_cases_20220818.csv")
display(df)

Screenshot 2023-04-25 at 14.24.39.png

initスクリプトの作成

注意
本機能がリリースされるまでに若干のタイムラグがあります。

これまでは、クラスターのinitスクリプトを利用するにはDBFSに.shを書き出してから設定する必要がありましたが、もっとお手軽に作成、設定ができるようになりました。

こちらを参考に。

ワークスペースで直接initスクリプトを記述します。

#!/bin/bash
apt-get --yes install libsndfile1

Screenshot 2023-04-25 at 14.50.32.png

クラスターのinitスクリプトの送信先でWorkspaceを選択し、initスクリプトのパスを入力して追加します。この際、パスは/Users/以降を記述してください。
Screenshot 2023-04-25 at 14.54.03.png

クラスターを起動するとinitスクリプトが実行されます。
Screenshot 2023-04-25 at 14.58.36.png

%pip install librosa
Python
# Beat tracking example
import librosa

# 1. Get the file path to an included audio example
filename = librosa.example('nutcracker')

# 2. Load the audio as a waveform `y`
#    Store the sampling rate as `sr`
y, sr = librosa.load(filename)

# 3. Run the default beat tracker
tempo, beat_frames = librosa.beat.beat_track(y=y, sr=sr)

print('Estimated tempo: {:.2f} beats per minute'.format(tempo))

# 4. Convert the frame indices of beat events into timestamps
beat_times = librosa.frames_to_time(beat_frames, sr=sr)
Downloading file 'Kevin_MacLeod_-_P_I_Tchaikovsky_Dance_of_the_Sugar_Plum_Fairy.ogg' from 'https://librosa.org/data/audio/Kevin_MacLeod_-_P_I_Tchaikovsky_Dance_of_the_Sugar_Plum_Fairy.ogg' to '/root/.cache/librosa'.
Estimated tempo: 107.67 beats per minute

動きました!

Databricksクイックスタートガイド

Databricksクイックスタートガイド

Databricks無料トライアル

Databricks無料トライアル

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?