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.
To achieve working knowledge of Data Frame,stack and unstack functions and groupby function.
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.
Step 2: Create the Data Frame
Taking small set of data for learning only and then creating Data Frame of it.
Step 3:Now start working with Data Frame.
Note :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 🙂
STACK UNSTACK and TRANSPOSE funtions
Step 1:Create the DataFrame
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 .
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.
transpose(): Simply does the transpose of the DataFrame i.e. converts rows to columns and columns to rows.
groupby() : groupby function lets you perform grouping operations like show below.
Step 1: Create Data with more number of columns than earlier.
Step 2: Now apply groupby function as below.
That’s enough for now.We will learn more in future posts.