As your Databricks notebooks have built in support for charts and visualizations.
The visualizations are available when you use the display command to view a data table as a result,
as either a PANDAS or a spark data frame in a notebook cell.
Okay.
So I’ve created a new Section seven folder called Visualizations and Dashboards.
And within that I have a notebook called One Visualizations and Dashboards, and I’m in that notebook
now.
So first let me read in the order, underscore details and monthly underscore sales data frames from
our gold layer using the read Pathway methods.
So I’ll create a variable called order underscore details, and then I will do swap dot read dot pak
and then I’ll pass in the file path.
So that will be file store slash, table, slash gold slash order, underscore details.
Then I will do the same for monthly sales.
I’ll assign it to a variable called monthly underscore sales sparked or red dot k file store tables
gold monthly underscore sales.
So as you can see, that’s worked.
Now, let me display the order, underscore details.
DataFrame.
Here is the dataframe displayed.
So notice I’ve used the display function to display the dataframe.
Now, if you click on this plus icon, you can either create a visualization or profile your data.
First, let me profile the data.
So this will take a moment, but when it completes, it basically profiles each column in your data
frame.
As you can see, the data frame has got one, two, three, four, five columns.
Four numerical columns and one categorical column.
For the numerical columns.
So if I just zoom out a little bit.
You can see the mean.
The standard deviation, the percentage of zeros, the minimum median and maximum values, as well as
a histogram showing the frequency of the values for the categorical columns.
You get the unique values, the top value, the frequency of the top value, the average length of the
values.
And then you get a line chart as well.
For all columns, you get the count of total values and the percentage of missing.
We have 0% missing for all the columns, which is a good thing.
Okay.
So we can add another visualization to by clicking this plus icon and you can also rename this.
So I’ll just call it data profiling.
And then if I click this plus icon, let’s add a visualization.
So you can select from a host of charts.
You have line charts, bar charts, area charts and more.
As you can see here, I’ll select a simple pie chart and display the sum of the total order amount by
store location.
So select pie chart and then for the x, I will select store name.
And then I will add a Y column, which will be the total order amount.
And then you can select your aggregation, which is some.
You can also also choose to group by.
So if I choose to group by store name, then as you can see, you’ve got a pie chart for each store.
But that doesn’t really make sense.
So I will not group by anything.
You can also change a direction from counterclockwise to clockwise and then you can do more as well.
You can also format it by changing the colors, add data labels, change the data labels, and so on.
I’ll just keep this chart for now as it’s just for an example.
Now, as you can see, it’s building the visualization and here it is.
And I can just call it quite a shot.
You can also edit the chart again by clicking here, and then you walk back to the visualization editor.
Now let me add another job.
I’ll do the daily sales by store type.
So to do that, I should probably create a line chart.
And then what I’ll do is for the X, I will do the date.
And then I will do the total order amount.
Sorry.
Actually, I will group it by the store name, but then I’ll add a y axis column.
Which would be the total order amount.
And then I can just do this on aggregation.
And again, you have the option to change a lot of the different features, the scale of the axes,
and then to sort the values, to not sort the values and so on.
So there are a lot of different options available to you, and depending on each chart, you’ll get
a different visualization editor with different options.
So let me save that.
And now, as you can see.
It’s building the chart and now we can see the sales by day.
For each store location.
So I can just rename this as sales by day.
And still location.
Here we go.
Now notice that I’ve displayed the order details DataFrame like this.
If you display it like this.
So if I just do order underscore details display.
You still have the option to create a visualization.
However, if I create a simple visualization, if I just do store name and then I just do total order
amount save.
You get an error.
DataFrame no longer exists if you’re using the data frame display.
Use display display with data frame passed in inside the parentheses instead.
So that’s just a note.
If you display your dataframe like this, you won’t be able to build visualizations.
But as you can see, it will still display the dataframe.
So if you want to create charts and visualizations, then pass your dataframe inside of the parentheses
of the display function.
Okay, So now let me add one more chart using the monthly sales data frame.
So I will just overwrite this and do display monthly undisclosed sales.
Okay, so let me just remove this visualization.
And I’ll add a new one.
So I’ll do a bar chart.
And then in the bar chart I will have the monthly uncheck uncheck horizontal chart because I’ll have
a vertical.
And I’ll have the month year and the total sales.
And as you can see, it’s actually already generated it for us.
And if you want to group by, you can as well.
So if you want to group by month year, then you get a different display.
But I’ll just keep it as this because the formatting is gone a bit strange.
So that will do for me.
And then I’ll just rename this visualization as total sales by month.
And here we go.
So now, as you can see, we’ve got a series of visualizations in this notebook.
So far, we’ve seen how to profile our data and create visualizations.
I’ll leave some documentation that contains information about the different chart types that you can
create in databricks.
As you can see here.
And Oliver as a link in the course resources.
Now let me show you how to build dashboards.
So if you wanted to be able to publish graphs and visualizations derived from notebook outputs and share
them in a presentation format with your organization, then you can create dashboards.
So if you simply select a visualization.
So here I have a visualization.
You also have a pie chart here.
So if you select this dropdown, you can add it to a dashboard.
Similarly, you can select here and add to Dashboard.
We don’t have a dashboard at present, so we’d have to create a new one.
So I’ll do that.
And now you can give your dashboard a title.
So I’ll just call it Demo Dashboard.
And now, as you can see, the visualization has been added to the dashboard and you can move it around
and you can also resize it.
So right now I’ve actually just added the data frame, but I don’t want to add the data frame.
So I’ll click on this X and we have nothing in the dashboard right now.
And if you want to go back to your notebook, you can click here.
Similarly, if you wanted to go back to the dashboard, you can go on view and then all of your dashboards
are displayed in the bottom here and you can click demo dashboard.
So right now it’s empty.
So let’s go back.
And now I will select this chart, click on the dropdown, add to Dashboard.
And as you can see, we now have our demo dashboard.
So I’ll add it to that.
So it’s been added, as you can see.
You can add more charts as well.
So I’ll add this chart as well.
So now if I go to view back to the dashboard.
As you can see, we now have two different charts.
We can resize them.
So if I want this one to be a bit longer across the bottom, I can.
And then this one, I can move around as well.
Actually leave it like this for now.
And also, if you click on the widget, you can add a title to the dashboard.
So I’ll just call it you can add a title to the chart.
So I’ll call it pie chart.
And then you can also show the run button.
So if you want to refresh this dashboard, then it will refresh the underlying notebook and populate
the new values as well.
Similarly, you can do that with all of them.
So show a title here and I’ll just do Line chop.
I’m just keeping it very simple, just for demo purposes.
So you’ve got pie chart lined up.
But obviously if you’re doing a proper dashboard, you would give more details as to what you want the
chart to show.
Similarly, you can also add text to your dashboard as well.
Let me show you how to do that.
So I’ll go back to the notebook and then what you can do is you can add markdown text.
So if I do percentage CMD and then I will write some text for my notebook and I’ll run that.
Now, as you can see, it’s markdown.
So what you can do is you can add it to the demo dashboard and then if you go and view, here’s the
text, you can then resize it.
And they move it around.
Similarly, if you go back to the Notebook.
You can also add a header so percentage MD and then if you do a hash, you can do title for my dashboard
and then run that CEL and then add it to the visualization.
Add it to the dashboard.
Then again, if you go back to the dashboard, you now have a title.
So you can again resize this, move it around.
Like this, and then you can get rid of this one if you wish.
And then you have a dashboard like so.
If you want to present your dashboard, you just click here.
So now this is what the dashboard looks like.
Of course, it’s not been formatted properly just because I’m doing it for demonstration purposes.
And I note the dashboard already has a title here, so you don’t necessarily need to create a title
with markdown text, but you can if you want to.
So let me go back to my notebook.
Similarly, you can also add text via the display HTML method where you can actually use HTML to further
format your text.
So if I run this cell, you can see I’ve got it in red now and then in a different font as well, and
you can add it to your dashboard.
So if I go to my dashboard.
You know, got some additional text here.
And then, as I’ve already shown you, you can present your dashboard here.
And then exit as well.
Now, obviously, this is a very messy dashboard.
In a real dashboard, you give property tools, charts, you’d format the dashboard a little bit more.
But this is just to show you that you can generate a dashboard from your databricks notebooks.
And I think for now, you can only share the dashboard with people who have a Databricks account.
But from my understanding, Databricks are looking to add a new feature in the near future which will
allow you to share this dashboard with external users.
So that was a lecture showing you how to create charts and dashboards via your databricks notebooks.
Please refer to the course resources where I’ve attached a series of links and further documentation
to help you with this.