top of page

Complete Pandas Tutorials for Data Science| Basics of Python

In this blog, I am going to post information about below mentioned topic of Pandas python’s library. Pandas is very powerful tool for data Munging and Wrangling. You can manipulate you data with different manner. First step for Machine Learning and Data Science is always Data Mining. Because every time we you have to understand the nature and properties of data. This will give you a better understanding of data and then you can use that useful data for your further process. Therefore, you have to give some intention to below mentioned topics. This topic will be very useful in coming advance things related to Machine Learning and Data science. Before working on Pandas you should require some basic knowledge about the Python, if you are not familiar to this stuff than you can go through with below mentioned blog for general understanding.


  1. What is a Data Frame in Python?

  2. How to Read a “csv” file using Panda?

  3. How we can know the shape of Data frames?

  4. How we can see Head and tail of providing data frames?

  5. How we can identify the Data type of every element with in Data frames?

  6. How we can get detailed information about Data Frames?

  7. How we can filter a row and columns using Pandas?

  8. How can we choose Different rows and Columns?

Data Frame: Very first step about Pandas is Data frame, before starting working on Pandas; you should know about Data frames. In pandas, you can represent your data in rows and columns. The structure of these rows and columns known as Data Frames. Data frame is two dimensional data structure and you can easily store data with different data types like int, float, data and more.

Here I have a data frame, which will help you to understand the pandas working. Data frame is containing the information about sale of products in different regions of this world. We have different parameters like total sale, total cost, order date, order channel etc. you can check with posted screenshot.


How to Read a csv file using Panda?


Note “Please upload the csv file to your Jupyter Notebook, Otherwise you have to enter complete location of your file” e.i (C:/users/dataset.csv).

How we can know the shape of Data frames?


Hope you have understood Data Frame, now you can also find the dimensions of your data frame using “df.shape” function. This function gives you a value about number of rows and columns exists in your data frame. In this example we have “100, 14” which means we have 100 Rows and 14 Columns are there. After reaching at advanced level, you have to work with millions of rows and columns. This function will help you in future.



How we can choose Head and tail of providing data frames?


If you want to read, first five Rows of Data frame than you can use “head” function with specific value and similar to the last 5 rows, you can use tail function.




How we can identify the Data type of every element with in Data frames?

A check on how pandas interpreted each of the column data types by requesting the Pandas “dtypes” attribute. Some time you need to change the data type of an element in this data frame, Check in the example, there is an element “ship date” which is an object data type, So in these conditions you have to change this into date data type. In coming blogs I will share about these python hacks to resolve such kind of issues.


How we can get detailed information about Data Frames?


Now if you want to know technical details about your Data frame than you can use “info” function.

The method Info() provides technical information about a Data Frame, so let’s explain the output in more detail:

  • It is indeed a Data Frame.

  • Different Data types

  • There are 100 entries, i.e. 100 rows.

  • Each row has a row label with values ranging from 0 to 99.

  • The Data frame has 14 columns.

  • The approximate amount of RAM used to hold the Data Frame provided as well.

How we can filter a Row using Pandas?


It is very easy to get values from a specific column of a data frame, Let’s check the example, Here we have defined a variable “total_cost” which is containing the column “Total Cost “ in given Data frame “df”2


Note: You can also select the multiple columns using this, you just have to mentioned here with “total cost” and column will added to new data frame called “total_cost”.

We have a column name “unit cost” in my data frame, you can check here, “unit cost” is containing price of different products or units. Therefore, if I want to select only those rows whose value is more than 100 than you can do this easily. Let us check with example


If you check the shape value now, it is decreasing from “100, 14” to “50, 14”

One more example for filtering the rows with specific values, in given data set we have a column, which known as “Sales Channel”. We have two different channels, which are “Online” & Offline and we have to choose only those rows, where Sale channel should be “Online”. Let us look on example first.



How can we choose Different rows and Columns?


If you want to select data frame from specific rows to specific columns, here we ca “iloc” function, suppose we have to select the data from row 4 to 25 and column 2 to 7. Jump to example.

We are defining the range to rows and columns. “4:25” refers to the row from 4 to 24 and similarly with columns.

Hope you have learn few basic things about Pandas, But it is just the basics roles of Pandas. In coming post, I will share advance level information about this Library. If you are interested in Data science and Machine Learning than start from today. Here are few links, which will help you for your first step.

Please comment and Share your experience during learning.


Share & Care: Technology Spiritual

 
 
 

Recent Posts

See All

Comments


bottom of page