Skip to content
Experiment with the AI assistant
Generative AI is coming to DataCamp Workspace! Go through this notebook to experience the AI-enabled functionality. In this example project, we'll be querying a database with unicorn company data to build a chart showing the countries with the highest amount in total funding.
Get the data
The first step is getting data. Rather than using SQL, we'll ask the AI assistant to generate the code for us!
- Click on the SQL cell below and select "Unicorn Companies" in the dropdown in the cell header.
- In the cell menu on the right-hand side, click on "Generate".
- In the input field that appears, type "Get a list of companies (name, country, and funding)".
- Hit Enter and see the code streaming in!
- Accept the suggestion and run the SQL cell.
Unknown integration
DataFrameavailable as
df
variable
SELECT company, country, funding
FROM companies
JOIN funding ON companies.company_id = funding.company_id;
Visualize the data
To visualize the DataFrame we got back in the previous step, let's ask the AI once more!
- Click in the Python cell below and click on "Generate" in the cell menu on the right-hand side.
- In the input field that appears, type "Plotly bar chart with top 10 countries by total funding".
- Hit Enter and see the code streaming in!
- Accept the suggestion and run the code cell.
import plotly.express as px
import pandas as pd
# Get the data
df = pd.read_sql_query("SELECT company, country, funding FROM companies JOIN funding ON companies.company_id = funding.company_id;", connection)
# Group by country and sum the funding
df_grouped = df.groupby('country').sum().reset_index()
# Sort by funding in descending order and get top 10
df_top10 = df_grouped.sort_values('funding', ascending=False).head(10)
# Create bar chart
fig = px.bar(df_top10, x='country', y='funding', title='Top 10 Countries by Total Funding')
fig.show()
May the AI force be with you! 🤖