- Seaborn Tutorial
- Seaborn - Home
- Seaborn - Introduction
- Seaborn - Environment Setup
- Importing Datasets and Libraries
- Seaborn - Figure Aesthetic
- Seaborn- Color Palette
- Seaborn - Histogram
- Seaborn - Kernel Density Estimates
- Visualizing Pairwise Relationship
- Seaborn - Plotting Categorical Data
- Distribution of Observations
- Seaborn - Statistical Estimation
- Seaborn - Plotting Wide Form Data
- Multi Panel Categorical Plots
- Seaborn - Linear Relationships
- Seaborn - Facet Grid
- Seaborn - Pair Grid
- Function Reference
- Seaborn - Function Reference
- Seaborn Useful Resources
- Seaborn - Quick Guide
- Seaborn - Useful Resources
- Seaborn - Discussion
Seaborn.load_dataset() method
The Seaborn.load_dataset() method is used to load in built datasets from the seaborn library. For the purpose of describing seaborn or creating reproducible examples for bug complaints, this function offers rapid access to a few example datasets.
It is not required for everyday use. To create an appropriate ordering for categorical variables, a minor amount of preprocessing has been conducted to some of the datasets.
Syntax
Following is the syntax of the seaborn.load_dataset() method −
seaborn.load_dataset(name, cache=True, data_home=None, **kws)
Parameters
The parameters of the seaborn.load_dataset() is seen below.
S.No | Parameter and Description |
---|---|
1 | Name Takes a string value and it is the name of the dataset. |
2 | Cache Take Boolean values and it is an optional parameter. If it is true, it tries to load from the local cache first and daves to cache is downloading is required. |
3 | Data_home This optional argument takes in a string value and it is the directory in which the cache data is set. |
Return value
This method returns a pandas dataframe.
Loading the dataset
order to plot graphs, we require data and in case, data is not available readily for your use in the required format and containing desired data, you can use the datasets present in the Seaborn library.
Seaborn contains various default datasets in addition to being a statistical charting toolkit. We'll use the one of the in-built datasets as an example of a default dataset.
Let us consider the tips dataset in the first example. The 'tips' dataset comprises information about people who have likely eaten at a restaurant and whether or not they left a tip for the servers, as well as their gender, smoking status, and other factors.
get_dataset_names() method helps to retrieve all the names of the in-built datasets available in Seaborn.
seaborn.get_dataset_names()
load_dataset() method helps to load the dataset with the name into a data structure.
Tips=seaborn.load_dataset('tips')
The above line of code helps to load the dataset with the name 'tips' into a data structure called tips. Thus, this method helps in loading the datasets from the library.
Example 1
Following is an example which loads the titanic dataset
import seaborn as sns import matplotlib.pyplot as plt dts= sns.load_dataset("titanic") dts.head() sns.relplot(data=dts, x="age", y="fare") plt.show()
Output
Following is the output of the above example −
Example 2
In the following example we are loading the tips dataset −
import seaborn as sns import matplotlib.pyplot as plt tips=sns.load_dataset("tips") tips.head() sns.catplot(data=tips,x="sex",y="tip",hue="time",height=5, aspect=.8) plt.show()
Output
This generates the following output −
Example 3
Let us see another example −
import seaborn as sns import matplotlib.pyplot as plt exercise=sns.load_dataset("exercise") exercise.head() g=sns.PairGrid(exercise) g.map_upper(sns.scatterplot) g.map_lower(sns.kdeplot) g.map_diag(sns.ecdfplot) plt.show()
Output
On executing, the above example generates the following example −
To Continue Learning Please Login
Login with Google