In this tutorial, you will prepare a short report on shopping trends based on your analysis of a .csv file with related data. You will learn how to perform the following basic tasks in Datalore:
Create your own workspace
Create a notebook
Connect data
Query and analyze your data
Build charts from your data
Add interactivity to your content
Share your results
Along the way, you will try some of Datalore's most powerful tools designed to improve your overall data analysis and code editing experience.
First steps
To get started, all you need to do is log into Datalore. You will find yourself on the Home page, in the default Private workspace, which is automatically created for every user after they log in for the first time.
You begin by creating your first own workspace. Own workspaces can be shared with other Datalore users, which is their main advantage over the 'unsharable' Private workspace.
The second step is creating a notebook where you will try most of Datalore's key features and tools.
Create your first workspace
In the lower left corner of the Home page, click the New workspace button. This will open the New workspace dialog.
In this dialog, provide a title for your new workspace and click the Create workspace.
Result
You are still on the Home page, but inside the newly created My First Workspace. In that workspace, you are at the moment in the Notebooks section, and it's empty for now. Your next step is adding a notebook here.
In the upper right corner of the screen, click the New notebook button.
For now, all you need to do is provide a title for your notebook in the respective text field and click the Create notebook button at the bottom of the dialog.
note
Creating a notebook is a procedure that may involve a few more steps as you can select a programming language and have a number of customizations. The full procedure can be found here.
Result
You created a Python language notebook, which is automatically opened in the editor. For now, the notebook contains only one code cell, which is empty.
Before your start editing your notebook
Make sure you complete each of the provided procedures in order to get the expected final result of this tutorial.
A few considerations
Main menu
Use the Main menu at the top of the screen to manage your notebook and customize editor settings. For example, you can choose a dark mode by selecting View | Dark mode. Also, you will be instructed to run the notebook (all of its cells). You can do it by selecting Run | Run all.
Shortcuts
In the procedures below, we provide UI-based instructions. However, for all described actions, you can use shortcuts. The full list can be found at Main menu | Help | Shortcuts. You can also open it by pressing ShiftF1.
Coding
We provide code examples for the instructions below for you to copy and paste into your notebook. However, you can code everything yourself and test how Datalore helps you along the way with its code assistance features. Find more details in this topic.
Connect and access your data
The next step is attaching a source of data to your new notebook and accessing that data in your code. As mentioned earlier, you'll be working with a .csv file containing shopping tend information.
Attach your data file to the notebook
The easiest way to attach a data file to your notebook is to drag it directly into the notebook editor.
Open the Attached data tool from the left-hand side of the editor.
Find the shopping_trends.csv file on the Files tab of Attached data.
Result
Your .csv file is attached to the notebook and can be accessed from code.
note
Your data options
Besides files, you can attach database and cloud storage connections, which are all accessible through the same Attached data tool. Find more details in this section.
Pull data from the attached file
After your file is attached to the notebook, you can read its data and save it to a DataFrame for further analysis.
Paste the code from the example below into the cell that you have in the editor.
import pandas as pd
my_table = pd.read_csv('shopping_trends.csv')
my_table
Execute the entered code by clicking the run icon in the upper left corner of the cell.
Result
You should get the following output for the executed code:
The table comes with a number of interactivity features. Find more details in this topic.
Try an SQL cell
Datalore provide a special type of cells to retrieve data from attached sources using native SQL statements. SQL cells are particularly useful when working with database connections, but they work just as well for individual data files like the one you attached a few steps ago.
Add an SQL cell to your notebook: click More under your first cell and select SQL.
In the added SQL cell:
Expand the list of data source types and select Dataframes.
Enter the following SQL statement to pull data from your file:
select*from shopping_trends.csv
Run this SQL cell.
Result
You will get a DataFrame that is identical to the one you produced using Python in the previous step.
note
Explore the full potential of SQL cells in this topic.
tip
We suggest deleting the SQL cell you just added to avoid having two identical DataFrames in the output.
Hover over the cell. You'll see a toolbar in the upper right corner.
Click Delete cell.
Provide your code with rich text
Make your project comprehensive and transparent by adding rich text to your code. This is where Datalore's Markdown cells come in handy.
Add a Markdown cell
Under the first cell click More and select Markdown.
In this new cell, provide a Markdown text that describes to your future notebook viewers what you want to do here. Try the input below:
# Shopping trends analysis, experiment
This experimental notebook analyzes shopping trends data and focuses on the following:
<ul><li>Preferred items</li><li>Preferred payment methods</li><li>Item distribution (by category, state, and season)</li></ul>
Run the code. You will see the following:
Result
You learned how to add rich text to your work in the notebook using Markdown cells. Feel free to add more cells where you find it appropriate.
note
Markdown cells come with a number of text editing features and can even be referenced in your code. Learn more about Markdown cells in this topic.
Analyze your data
Now you can dig deeper into your data and visualize the findings.
Write your first code to start analyzing data
In this procedure, you will get a more specific data by ranking all items from most purchased to least purchased.
Click Insert code cell under your last cell.
tip
Alternatively, you can right-click anywhere in the editor and select Insert code cell below from the popup menu.
Run the code in the cell. You'll get a DataFrame like this:
Result
You get a new DataFrame with the results of your Python-driven analysis of the attached dataset.
Visualize your data without coding
In this procedure, you will learn how to visualize your data using different types of charts and export them as code.
In the cell with your DataFrame from the previous procedure, switch to the Visualize tab. You will get a point chart based on your DataFrame content.
Point chart is the default setting. Change the type of the plot on the left side of the tab to try other options. For example, this is how a bar chart looks for this table.
This automatically built chart is not part of your code and therefore cannot be saved or shared as part of the notebook. However, you can export it as code. This will allow you to edit the chart programmatically or share it together with the rest of the notebook.
Click export to code cell on the left side of the tab.
tip
Alternatively, you can export it to a chart cell, but this type of cells is covered separately in this topic.
This will add a cell to your notebook with a Python code that generates the selected chart. Now, this chart is part of the notebook code and can be edited or shared with the rest of the content. Run the cell to see the result.
Result
You added a new Python cell that builds a chart for your dataset without writing any code manually.
Empower your coding with AI
In this part of the tutorial, you will learn how to use the AI functionality of Datalore to expand your coding abilities and edit your notebook faster.
Let's take a look at payment method distribution according to our data and build a pie chart for it. Pie charts are not available on the Visualize tab of Datalore code cells, meaning you need to provide your own code to build that kind of chart. That's where you might want to use the Ask AI tool available in all Datalore code cells.
Build a pie chart using AI support
Add a new code cell to your notebook (0B shortcut).
On the toolbar of the cell, click the Ask AI icon. A prompt box will appear in the cell.
Enter the prompt in the image below and click the Generate icon.
In the Review of generated prompt dialog, you can select which parts of the notebook will be sent for analysis for AI to generate a code suggestion. For now, just click the Submit button (for all notebook content to be analyzed).
Soon you can see a code suggestion generated by AI. Click Accept and run to add the code to the cell and run it as-is.
Result
You used Datalore's native AI assistant to further analyze your data and build a pie chart based on your findings. Now, you know how to work with code cells without writing any code yourself.
Add interactivity to your notebook
With massive datasets, there's a natural need to be able to select what data you want to see in the output, and how you want to see it. And of course, it is important that you do not have to change the code every time you want to tweak data presentation in your notebook.
Datalore solves this problem by helping you make your notebooks interactive. You add controls like dropdowns, sliders, or checkboxes to enable viewers of your notebook to change data presentations in a few clicks.
In this par of the tutorial, you will build two charts that will be updated using a dropdown control. The original dataset covers data across all states of the USA. With this dropdown, you will only view data for the states you select.
Add a dropdown control to filter your data
Begin by adding and setting up a dropdown control. In a nutshell, this dropdown control will draw values from the Location column to allow you to choose from all 50 states presented in the original table.
First, create an array that will include all values (state names) from the Location column. Add a code cell and paste the following code:
import numpy as np
states = list(set(my_table.Location.values))
states = np.array(states)
states = np.sort(states)
states
Now, you have an array to feed values to your future dropdown.
Add a dropdown cell: click More and select Dropdown.
This will add a new cell to your notebook and open the Dropdown dialog
Configure your dropdown control:
Provide a label for the control. It should be something meaningful because this is the dropdown name that will be displayed in the notebook.
In the Variable field, provide a name for the variable that will store the selections made with this dropdown. In our case, that's the names of the states. This variable will be used in the analysis of your data, and it is that variable that will filter the data.
It is important that you call this variable state. This name will be used in the next procedure.
Switch to the Dynamic tab. This is required to select a list variable that will feed the values that your dropdown will provide as selections.
Expand the list and select states, which is the array of state names you created in the previous procedure.
Select the Multiselect checkbox to enable selecting more than one state name from the dropdown.
Click the Apply button to close the dialog.
The dropdown cell that you added is now updated and can be used to select the respective values. Select the first two states from the list.
Result
You created a dropdown that allows to select values from one of your original table's columns. You will use this control to filter your dataset interactively without changing the code every time you want to view your data differently.
note
Learn about all types of interactive controls in this topic.
Apply interactively set values to your code
In this procedure, you will create two charts where source data is filtered by the selections of your dropdown.
The charts will display the following analysis results for any number of selected states:
Total purchases distributed over categories
Total purchases distributed over seasons
First, filter the original DataFrame by the states that will be selected using your dropdown. You will do this by using the state variable that contains values selected with your dropdown.
tip
This will only work if you used the state name in this step.
Now, you have the filtered_table_by_state DataFrame with data for the selected states only. That's the DataFrame you will be using to build the two charts.
For your first chart, count purchases in each category and compare them in the selected states:
Add another code cell.
Paste the code below.
grouped_state_items = filtered_table_by_state.groupby(['Category','Location'])['Item Purchased'].count().reset_index()
grouped_state_items.columns =['Category','Location','Total of purchases']import seaborn as sns
plt.figure(figsize=(12,6))
sns.barplot(x='Category', y='Total of purchases', hue="Location", data=grouped_state_items)
plt.title('Categorized total of purchases (by state)')
plt.legend(loc='upper right')
plt.show()
Select Main Menu | Run | Run all to execute the entire notebook. This is required to make sure the last pieces of code use the values based on your earlier selection of 'Alaska' and 'Alabama'.
You should have the following result.
Compare purchases in the selected states by season:
Add one more code cell and paste the following code:
total_items = filtered_table_by_state.groupby(['Season','Location'])['Item Purchased'].count().reset_index()
unique_locations = filtered_table_by_state['Location'].unique()for location in unique_locations:
data = total_items[total_items['Location']== location]
plt.figure(figsize=(10,6))
plt.pie(data['Item Purchased'], labels=data['Season'], autopct='%1.1f%%')
plt.title('Season distribution of purchases: '+ location)
plt.show()
Run the notebook one more time to view the results. For the same selection of states, 'Alaska' and 'Alabama', you should have this:
Make sure the interactivity works:
Select different states from the dropdown.
Run the notebook again.
The outputs should have updated charts with data for the newly selected locations.
Result
You produced a few more charts, which are updated interactively using the dropdown created earlier.
This is made possible through the use of a variable that stores results of the last interactions with the dropdown.
This allows you to have data presentations that can be changed without editing your code in the input.
Share your result
Let's suppose that for the time being your part of analysis work on this project is done, and you want to share your notebook with your team members. With collaboration as one of its top priorities, Datalore provides a number of options for you to choose how exactly you want to do it.
In the next procedure, you share this notebook by granting edit access to any other Datalore users with a shareable link.
Share your notebook using a link
In the editor, click the share icon in the upper right corner of the editor. This will open the Share [notebook_name] dialog.
Click No access link to expand the list of access types and select Edit access link.
The link is created. You can copy it or click it to open the notebook with editing rights in a new browser tab.
Result
You shared your notebook by granting edit access to anyone who has the generated link.
You can track actions by other contributors in real-time: avatars of other people currently working on your notebook will be visible next to your own. Collaborators can also leave comments (more details here).
All changes made by other editors will be saved to your notebook. You can track all these changes and roll back to earlier versions of the notebook using the History tool (Main menu | Tools).
note
You can also use this dialog to share your notebook by sending email invitations to specific users whose contacts you will provide. Find more details in this topic.
Publish you notebook
The final part of this tutorial is presenting your notebook as an interactive report. You will publish your notebook as a standalone web page that viewers can interact with to update the charts you prepared. The key difference between a shared notebook and a published notebook is that the latter option is aimed at the audience that is only interested in outputs. Report viewers are not expected to look into the code or change it. While notebooks are shared for further collaboration on them, they are published to make the results of data analysis available to a wider audience.
Build a report
This procedure explains how to use a tool called Report builder to design a report based on your notebook.
Click the Build report button in the upper right corner of the editor. You will see something like this:
In short, the tool works like a canvas where you place and arrange content of your notebook cells. To the left of the canvas, you have a cell list, where you select what inputs and outputs you want to place on the canvas.
The canvas also serves as a mockup of your future report so you know what your notebook looks like when published.
The canvas already has some content placed on it, but you need to make sure that's exactly what you want to show. For example, you don't want any tables included in the report. You just want to present the charts. Also, no code inputs are expected to be shown in this report.
In the Cell list menu, select the following content:
Markdown cell output with the introductory text (added here)
Code cell output with the exported bar chart (added here)
Code cell output with the pie chart you built using AI (added here)
Code cell outputs with charts updated interactively (added here)
note
This procedure has no effect on how the notebook code is executed. Whichever cells you select for the canvas, the code for calculation remains the same.
Now, with the required content on the canvas, re-arrange some of its segments to optimize the look of your future report:
Reduce the cell with the bar chart by dragging the resize handles (displayed when hovering over the cell). This will free up a lot of area on the canvas.
Click the Arrange button in the upper right corner of the Report builder to re-arrange the content and remove the unoccupied area.
Resize the cell with the pie chart (Distribution of Payment Methods) to remove the unoccupied area.
Drag the pie chart to the right of the bar chart.
Click the Arrange button again to 'pull up' the rest of the content closer to the resized cells.
Result
Your notebook is now ready to be published as a report. This report will feature the content that you specifically selected for publishing.
Learn more about working in the Report builder in this topic.
Publish your notebook as an interactive report
In this procedure, you publish the report that you built in the previous procedure. This will be an interactive report, which will allow its users to change data views using the dropdown control you added earlier in this tutorial. It is assumed that you're still in the Report builder and have completed the steps described here.
Click the Publish report button under the Cell list. This will open the Publish [report_name] dialog.
In the dialog:
Expand the list under Report type and select Interactive report.
Select the Reactive mode checkbox to ensure interactivity.
Click the Publish button.
You will get a confirmation window.
In the Confirmation window, click the Open report button.
Result
You have published your notebook as an interactive report. Try the dropdown control to make sure a new selection of values will change the data views.
note
You can also publish the notebook as static reports, which provide fixed data views. Find more about reports in this topic.
Keywords
getting started, first notebook, demonstration, demo notebook, how to begin, quickstart, how to use Datalore, Datalore guide, basic procedures
Thanks for your feedback!
Was this page helpful?
Cookie Settings
Our website uses some cookies and records your IP address for the purposes of accessibility, security, and managing your access to the telecommunication network. You can disable data collection and cookies by changing your browser settings, but it may affect how this website functions. Learn more.
With your consent, JetBrains may also use cookies and your IP address to collect individual statistics and provide you with personalized offers and ads subject to the Privacy Notice and the Terms of Use. JetBrains may use third-party services for this purpose. You can adjust or withdraw your consent at any time by visiting the Opt-Out page.