Lab 03

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 32

Pandas,

Matplotlib,
seaborn
Task no. 1:

Create a Dictionary and convert them into data frames also check its datatype

Data Frames:

Two-dimensional, size-mutable, potentially heterogeneous tabular data.

Data structure also contains labeled axes (rows and columns). Arithmetic operations align on
both row and column labels. Can be thought of as a dict-like container for Series objects. The
primary pandas data structure.

Task no. 2:

Demonstrate the use of describe function for a data frame

Describe():The describe() method is used for calculating some statistical data like percentile,
mean and std of the numerical values of the Series or DataFrame. It analyzes both numeric
and object series and also the DataFrame column sets of mixed data types.
Task no. 3:

Demonstrate the use of head function

Head():

head() returns the first n rows(observe the index values). The default number of elements to
display is five, but you may pass a custom number.

Task no. 4:

Demonstrate the use of tail function

Tail(): tail() returns the last n rows(observe the index values). The default number of
elements to display is five, but you may pass a custom number.
Task no. 5:

Demonstrate the use of info function

Info():

The info() function is used to print a concise summary of a DataFrame. This method prints
information about a DataFrame including the index dtype and column dtypes, non-null values
and memory usage. Whether to print the full summary
Task no. 6:

Convert the data frame in a variable to CSV file

Data.to_csv:

Pandas DataFrame to_csv() function converts DataFrame into CSV data. We can pass a file
object to write the CSV data into a file. Otherwise, the CSV data is returned in the string
format.

CSV File:

Task no. 7:
Remove the indexes from the csv file

If we want to convert this DataFrame to a CSV file without the index column, we can do it
by setting the index to be False in the to_csv() function. As seen in the output, the DataFrame
does have an index, but since we set the index parameter to False , the exported CSV file
won't have that extra column.

CSV File:

Task no. 8:
Read from CSV File

read_csv is an important pandas function to read csv files and do operations on it.

Task no. 9:

Use describe,head,tail and info function for CSV file


Task no. 10:

Access a column by its name


Task no. 11:

Access the 1st element of a column

Task no. 12:

Update a value in the column


Task no. 13:

Find the columns and indexes in a data frame

DataFrame.columns
The column labels of the DataFrame.
DataFrame.index
The index (row labels) of the DataFrame.

Task no. 14:

Create a series of 50 random numbers and check their data type and shape

Series is a one-dimensional labeled array capable of holding data of any type (integer, string,
float, python objects, etc.). The axis labels are collectively called index.
Task no. 15:

Create a 50 x 5 data set from random values


Task no. 16:

Find the minimum maximum and mean values column wise in a dataset

Task no. 17:

Find the maximum value in 1st column


Task no. 18:

Convert the dataset into numpy array and also take transpose of it
Task no. 19:

Change names of the columns.


Task no. 20:

Display column B and C from the dataset


Task no. 21:
Use head function

Task no. 22:


Demonstrate the use of iloc function
Iloc:iloc is integer position-based, so you have to specify rows and columns by their integer
position values (0-based integer position).
Task no. 23:

Print column A to C and fimd the value on 0,0

Loc:

loc is label-based, which means that you have to specify rows and columns based on their row
and column labels.
Task no. 24:

Print 1st 12 elements of column 2 and 4


Task no. 25:

Import matplotlib

Task no. 26:

Use plot and show functions to create a graph

Plot():

The plot() function is used to draw points (markers) in a diagram.

By default, the plot() function draws a line from point to point.

The function takes parameters for specifying points in the diagram.

Parameter 1 is an array containing the points on the x-axis.

Parameter 2 is an array containing the points on the y-axis.


Task no. 27:

Add labels and title to the graph

With Pyplot, you can use the xlabel() and ylabel() functions to set a label for the x- and y-axis.

With Pyplot, you can use the title() function to set a title for the plot.
Task no. 28:

Plot using 3 variables on a single graph


Task no. 29:

Change the color linestyle and linewidth of the graph

You can use the keyword argument linestyle, or shorter ls, to change the style of the plotted
line

You can use the keyword argument linewidth or the shorter lw to change the width of the line
Task no. 30:

Plot using subplot

With the subplots() function you can draw multiple plots in one figure
Task no. 31:

Print the marks of students w.r.t their names using Dictionary

Task no. 32:

Plot a horizontal bar graph

If you want the bars to be displayed horizontally instead of vertically, use the barh() function
Task no. 33:

Plot using scatter function

The scatter() function plots one dot for each observation. It needs two arrays of the same
length, one for the values of the x-axis, and one for values on the y-axis
Task no. 34:

Plot a histogram

A histogram is a graph showing frequency distributions.


Task no. 35:

Demonstrate the use boxplot

A Box Plot is also known as Whisker plot is created to display the summary of the set of data
values having properties like minimum, first quartile, median, third quartile and maximum. In
the box plot, a box is created from the first quartile to the third quartile, a vertical line is also
there which goes through the box at the median. Here x-axis denotes the data to be plotted
while the y-axis shows the frequency distribution.

Task no. 36:

Demonstrate the use of violin plot

A violint plot allow to visualize the distribution of a numeric variable for one or several
groups. Seaborn is particularly adapted to build it thanks to its violin() function. Violinplots
deserve more attention compared to boxplots that can sometimes hide features of the data.
Task no. 37:

Demonstrate the use of pie function

You might also like