Pandas Library For Beginner

In this tutorial, we going to learn pandas library in python this tutorial consists of series, reading datasets, and print datasets. In this tutorial we’ll complete beginner subjects in pandas, Let’s pass to the first subject.

Reading Dataset

firstly, we’ll read the dataset with pandas, for this, we can use 2 different dataset types CSV files and xlsx files. There are 2 different functions for these two data sets, these are read_csv and ExcelFile functions.

Printing Dataset

Now, we going to look at the example dataset in the Jupyter Notebook, if you don’t know about Jupyter Notebook you can read this article, then we’ll print example datasets in Jupyter Notebook from Visual Studio Code.

If you want this CSV file you can download it from here. Here, we read the CSV file, and first, we write all data with print function then, we printed just 5 rows with head function.

Series Statement In Pandas

Now, we know reading datasets and printing this dataset on the console, so we going to look at the series statement. pandas series are one-dimensional strings that can contain any data type.

You can think of this concept as a single column in excel, you can add as many lines as you want, but it should be a single column. You can check a simple example is given below.

0    a
1    b
2    c
3    d
dtype: object

this series in the example above stores a single data type, We can also use a list, array, or NumPy array to create such a series. Let’s create a few more examples to understand this concept, using pandas.

Making New Series With List

In this section, we will create a series with a list also going to examine the series function then we’ll create series with an array for the learning series function.

0   a
1   1
2   2
3   1.25
4   True
5   abc
dtype: object

Let’s examine this Series function, this function converts the argument to a series. The entered argument can be a list, array, or any multivalue holder.

Making New Series With Array

in this part, we going to use the Numpy library but you don’t need to know, you can understand in code. Let’s look at this example.

Here, we will take the same series as the example above, the purpose here is to show that you can also use data types outside the list.

Subplotting In Series

In Series, you can call a data by index, all you have to do is find the correct index and add it to the index argument.

pd.Series([1 , 2 , 3] , index = [0 , 1]) # We selected first and second index
data = pd.Series([1 , 2 , 3 , 4 , 5]) # We selected from 0 to 3
data[0:3]
data = pd.Series([1 , 2 , 3 , 4 , 5]) # We selected from 0 to 3
data[:3]

While we have seen the basic sub plotting operations above, we can change the names of these indexes then we going to the simple manipulation function for the series function.

pd.Series([1 , 2 , 3 , 4] , index = ["a" , "b" , "c" , "d"])

In this way, I changed my index names and now I can access the data I want by typing these index names. Let’s pass on the series manipulation.

Series Manipulation

First, we start with the learn mean function, we use this function to average the series gather all the values in the list then divide by the index number.

data = pd.Series([1 , 2 , 3])
data.mean()

Second, we going to look sum function, this function sums all the values in the series, it is used as the mean function.

data = pd.Series([10 , 20 , 30])
data.sum()

CONGRATULATIONS, YOU PASSED FIRST PANDAS TUTORIAL FOR BEGINNER!

Leave a Reply

Your email address will not be published. Required fields are marked *