Python Seaborn get_dataset_names() Method
Last Updated :
25 Apr, 2024
Seaborn is a Python data visualization library based on Matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. In this article, we will learn about the Python seaborn.get_dataset_names() Method.
What is the Seaborn get_dataset_names() Method?
The seaborn.get_dataset_names() method is used to retrieve the complete list of names of all the built-in or sample datasets provided by the seaborn library. The datasets provided by the Seaborn library are returned as a Pandas dataframe which can later be used for creating visualization or analytical reports.
Syntax of Python Seaborn get_dataset_names() Method
seaborn.get_dataset_names()
Parameters: This method doesn't take parameters.
Returns: It returns a list of names of built-in datasets in seaborn
Seaborn get_dataset_names() Method Examples
Below are examples of Python seaborn.get_dataset_names() Method:
- Loading and Visualizing a Dataset
- Checking Dataset Availability
- Looping Through Available Datasets
Loading and Visualizing a Dataset
In this example, below code uses seaborn to access built-in datasets. It retrieves the list of available datasets and loads the 'iris' dataset. Finally, it displays the first few rows of the 'iris' dataset for visualization.
Python3
import seaborn as sns
# Get the list of available datasets
datasets = sns.get_dataset_names()
# Load the 'iris' dataset
iris = sns.load_dataset('iris')
print(iris.head())
Output
sepal_length sepal_width petal_length petal_width species
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa
Checking Dataset Availability
In this example, below code imports seaborn and retrieves the list of built-in datasets. It checks if the 'titanic' dataset is included in the list and prints a message indicating its availability status.
Python3
import seaborn as sns
# Get the list of available datasets
datasets = sns.get_dataset_names()
if 'titanic' in datasets:
print("The 'titanic' dataset is available.")
else:
print("The 'titanic' dataset is not available.")
Output
The 'titanic' dataset is available.
Looping Through Available Datasets
In this example, below code imports seaborn and fetches a list of built-in datasets. It then iterates through each dataset in the list, printing out the name of each dataset.
Python3
import seaborn as sns
# Get the list of available datasets
datasets = sns.get_dataset_names()
for dataset in datasets:
print(dataset)
Output
anagrams
anscombe
attention
brain_networks
car_crashes
diamonds
dots
dowjones
exercise
flights
fmri
geyser
glue
healthexp
iris
mpg
penguins
planets
seaice
taxis
tips
titanic
Similar Reads
Python seaborn.load_dataset() Method Python seaborn.load_dataset() method allows users to quickly load sample datasets provided by Seaborn for practicing and experimenting with data visualization techniques. In this article, we will understand about Python seaborn.load_dataset() method. Python seaborn.load_dataset() Method SyntaxBelow
2 min read
Pandas Dataframe/Series.head() method - Python The head() method structure and contents of our dataset without printing everything. By default it returns the first five rows but this can be customized to return any number of rows. It is commonly used to verify that data has been loaded correctly, check column names and inspect the initial record
3 min read
Pandas Dataframe/Series.head() method - Python The head() method structure and contents of our dataset without printing everything. By default it returns the first five rows but this can be customized to return any number of rows. It is commonly used to verify that data has been loaded correctly, check column names and inspect the initial record
3 min read
How to use datasets.fetch_mldata() in sklearn - Python? mldata.org does not have an enforced convention for storing data or naming the columns in a data set. The default behavior of this function works well with most of the common cases mentioned below: Data values stored in the column are 'Dataâ, and target values stored in the column are âlabelâ.The fi
2 min read
Python | How to get function name ? One of the most prominent styles of coding is following the OOP paradigm. For this, nowadays, stress has been to write code with modularity, increase debugging, and create a more robust, reusable code. This all encouraged the use of different functions for different tasks, and hence we are bound to
3 min read
Python | How to get function name ? One of the most prominent styles of coding is following the OOP paradigm. For this, nowadays, stress has been to write code with modularity, increase debugging, and create a more robust, reusable code. This all encouraged the use of different functions for different tasks, and hence we are bound to
3 min read