Overview:

In learning post we have seen how to work with data.Now we are going deep into the subject.

1.In this post we will dive a bit deeper into the functionality of Data Frames.We will get to know what is data frame,simple method to create our own Data Frame,delete and add rows,columns,rename them and many more functionality.

2.We will have a brief knowledge of stack and unstack functions in this post.

3.We have heavily used groupby function in earlier post.In this post we will get details about it.

Mission:

To achieve working  knowledge of Data Frame,stack and unstack functions and groupby function.

DATA FRAME:

A Data Frame is a tabular data structural that comprises of rows and columns.Usually columns are named and rows are numbered but if you name rows, these are converted to dictionary for faster access.Data Frame has a feature over Matrices.Matrices can have only one type of data while Data Frame can have different type of data.

Lets go and work with it ! 😉

Step 1:Import the required libraries and functions.

p3f1

Step 2: Create the Data Frame

Taking small set of data for learning only and then creating Data Frame of it.

p3f2

Step 3:Now start working with Data Frame.

1.Add columns.

p3f3

p3f4Note :The number of elements in the column in the new column should be equal to the number of rows other wise it raises an error.You have one more way that is directly assign a value  that will be iterated through whole column 🙂

p3f5

p3f6

2.Delete column in Data Frame.
p3f7

p3f8

3.Functioning with already added columnsp3f9

p3f10

4.Slicing of data from Data Frame using a loc and iloc function

p3f11p3f13

p3f14

p3f15

5.Using head and tail function.p3f16

p3f17

STACK UNSTACK and TRANSPOSE funtions

Step 1:Create the DataFrame

p3f21Step 2: Start working on it 😉

stack(): stack() is a part of both Series and DataFrame object.The process of stacking pivots a level of column labels to the row index.It actually does multi indexing .

p3f22

unstack(): unstack() is too a part of Series and DataFrame object.It does the process unstacking i.e stacking level of row labels to the column index.It also does multi indexing.

p3f23

transpose(): Simply does the transpose of the DataFrame i.e. converts rows to columns and columns to rows.

p3f24

p3f25

GROUPBY:

groupby() : groupby function lets you perform grouping operations like show below.

Step 1: Create Data with more number of columns than earlier.

p3f31

Step 2: Now apply groupby function as below.

p3f32

That’s enough for now.We will learn more in future posts.

Advertisements