Python Pandas Library

Serap Baysal
CNK Tech
Published in
3 min readMar 15, 2021

After Numpy library, I will explain what Pandas library is, why useful and why we should use this.

Pandas library created for studying data frames. So, what is data frames? Data frames are excel files, this files has datas.

In Pandas, transition from file to file (.csv or .txt files) is easy. Also examining and saving files easy too.

Files can have missing values. If you studying with real world datas, you can see that. But that’s not problem on Pandas.

Pandas usually using with time series too. If you go to the link following, you can see what time series:

https://en.wikipedia.org/wiki/Time_series

Let’s look at Pandas a little more!

Firstly we importing the pandas library in our project with import pandas as pd. Than, we’ll creating a dictionary for example. Like this:

dictionary = {“NAME”:[“Ali”,”Veli”,”Kenan”,”Hilal”,”Ayse”,”Evren”],

“AGE”:[15,16,17,33,45,66],

“SALARY”:[100,150,240,350,110,220]

}

For using Pandas, we have to transform this dictionary to a data frame. If we write dataFrame1 = pd.DataFrame(dictionary) in our code we can use that.

You don’t have to use Spyder to writing codes, but if you do, you can see this in variable explorer:

You can see the diffrence between dictionary and data frame.

This data frame is too small but in real world’s datas are complicated. So if we want to see data frame’s first 5 datas, just need to write dataFrame1.head(). After that, you can print and see data.

Also for see data’s last 5 record, we will write dataFrame1.tail().

dataFrame1 = pd.DataFrame(dictionary)

dataFrame1.columns

This code gets column names (name,age,salary), It’s important because we need this about filtering

dataFrame1.info()

This code gets dataframe type, samples in dataframe, index, data types, memory usage, count of column and their names (except index).

dataFrame1.dtypes gets dataframe type.

dataFrame1.describe() gets numeric features. Like columns’s count, mean, min, max etc.

Now, we will going to details

If we want to see just special column in data frame, for example NAME column, we’ll write dataFrame1[“NAME”] or dataFrame1.NAME.

So, let’s look what to do for creating a new column:

dataFrame1[“New_Feature”] = [-1,-2,-3,-4,-5,-6]

There’s important think, our column’s name haven’t got space. If we do that, It’s not an error but if we write like dataFrame1.New Feature, it has an error.

Our data frame look like this, now:

If you know about SQL, our new subject is like that. Filtering data is important in Data Science.

filtre1 = dataFrame1.SALARY > 200

This code filter our data to salary.

.concat function concatinate our diffrent datas to vertical or horizontal.

That’s it, now we will know about Pandas mostly. Thanks to reading!

NOTE: In pandas, we use object. Object means string. So, if you write type(variable), you can see object type.

--

--