- Seaborn - Pair Grid
- Seaborn - Facet Grid
- Seaborn - Linear Relationships
- Multi Panel Categorical Plots
- Seaborn - Plotting Wide Form Data
- Seaborn - Statistical Estimation
- Distribution of Observations
- Seaborn - Plotting Categorical Data
- Visualizing Pairwise Relationship
- Seaborn - Kernel Density Estimates
- Seaborn - Histogram
- Seaborn- Color Palette
- Seaborn - Figure Aesthetic
- Importing Datasets and Libraries
- Seaborn - Environment Setup
- Seaborn - Introduction
- Seaborn - Home
Function Reference
Seaborn Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Seaborn - Importing Datasets and Libraries
In this chapter, we will discuss how to import Datasets and Libraries. Let us begin by understanding how to import pbraries.
Importing Libraries
Let us start by importing Pandas, which is a great pbrary for managing relational (table-format) datasets. Seaborn comes handy when deapng with DataFrames, which is most widely used data structure for data analysis.
The following command will help you import Pandas −
# Pandas for managing datasets import pandas as pd
Now, let us import the Matplotpb pbrary, which helps us customize our plots.
# Matplotpb for additional customization from matplotpb import pyplot as plt
We will import the Seaborn pbrary with the following command −
# Seaborn for plotting and stypng import seaborn as sb
Importing Datasets
We have imported the required pbraries. In this section, we will understand how to import the required datasets.
Seaborn comes with a few important datasets in the pbrary. When Seaborn is installed, the datasets download automatically.
You can use any of these datasets for your learning. With the help of the following function you can load the required dataset
load_dataset()
Importing Data as Pandas DataFrame
In this section, we will import a dataset. This dataset loads as Pandas DataFrame by default. If there is any function in the Pandas DataFrame, it works on this DataFrame.
The following pne of code will help you import the dataset −
# Seaborn for plotting and stypng import seaborn as sb df = sb.load_dataset( tips ) print df.head()
The above pne of code will generate the following output −
total_bill tip sex smoker day time size 0 16.99 1.01 Female No Sun Dinner 2 1 10.34 1.66 Male No Sun Dinner 3 2 21.01 3.50 Male No Sun Dinner 3 3 23.68 3.31 Male No Sun Dinner 2 4 24.59 3.61 Female No Sun Dinner 4
To view all the available data sets in the Seaborn pbrary, you can use the following command with the get_dataset_names() function as shown below −
import seaborn as sb print sb.get_dataset_names()
The above pne of code will return the pst of datasets available as the following output
[u anscombe , u attention , u brain_networks , u car_crashes , u dots , u exercise , u fpghts , u fmri , u gammas , u iris , u planets , u tips , u titanic ]
DataFrames store data in the form of rectangular grids by which the data can be over viewed easily. Each row of the rectangular grid contains values of an instance, and each column of the grid is a vector which holds data for a specific variable. This means that rows of a DataFrame do not need to contain, values of same data type, they can be numeric, character, logical, etc. DataFrames for Python come with the Pandas pbrary, and they are defined as two-dimensional labeled data structures with potentially different types of columns.
For more details on DataFrames, visit our
on pandas. Advertisements