Installing Seaborn Open up the terminal
Install Seaborn by running the following command:
pip3 install seaborn
Configuring access to MongoDB Atlas Movies collection Sign in to your MongoDB Atlas account at https://www.mongodb.com/cloud/atlas (or create an account if you don't have one).
Open your terminal or Jupyter Notebook.
Install the PyMongo library if you haven't already by running the following command:
pip3 install pymongo
Import the necessary libraries in your Python script:
from pymongo import MongoClient
import seaborn as sns
import matplotlib.pyplot as plt
Set up a connection to your MongoDB Atlas cluster using the connection string you copied earlier:
connection_string = "mongodb+srv://<username>:<password>@<cluster-address>/test?retryWrites=true&w=majority"
client = MongoClient(connection_string)
Access the "movies" collection in the "sample_mflix" database:
db = client['sample_mflix']
collection = db['movies']
Query the data from the collection:
# Retrieve the data from MongoDB
documents = collection.find({})
Convert the MongoDB documents to a pandas DataFrame:
import pandas as pd
df = pd.DataFrame(list(documents))
Perform any necessary data cleaning and transformation on the DataFrame.
Use Seaborn to create visualizations based on the data in the DataFrame. For example, you can create a scatter plot as follows:
sns.scatterplot(data=df, x='year', y='imdb.rating')
plt.show()
Run your Python script or execute the code in your Jupyter Notebook to visualize the data from the MongoDB Atlas Movies collection using Seaborn.