Python Basics : Part 12 – Methods

The most common and widely used feature of python programming for data science is methods. You will see the usage of methods quite often while you dive further into data science with python.

Lets go ahead and create a string :

In [1]: s=' hello! Welcome To Python Crash Course'
In [2]: s.lower()
Out[3]: 'hello! welcome to python crash course'

It’s so simple isn’t it ? The lower method on a string will convert all the characters to lower case. You can try the s.upper() method and see if the method changes your string to upper case. There are several methods of a string which can be found by pressing tab in jupyter notebook after the dot symbol ( s. ), you can try out various methods available.

Lets go over the split method.

In[4] : s.split()
Out[5]: ['hello!', 'Welcome', 'To', 'Python', 'Crash', 'Course']

The split functions splits the strings on the white space. If you need to split the dataset based out of ‘!’ then you can pass the ! mark within quotes and within the split function. The method will split the string where it finds the ! mark.

In [6]: s.split('!')
Out[7]: ['hello', 'Welcome To Python Crash Course']

You can try and use methods on strings, dictionaries and lists. Lets try a method on a list.

In [8]: list=[1,2,3]
In [9]: list.pop()
Out[10]: 3

The pop method removes the last component/element from the list permanently. If there is a need to pop a particular item of your choice, you have to target the items index and pass the value within the pop functional brackets.

In [11]: list
Out[12]: [1,2]

Here we come to an end of the python crash course for data science. These 12 modules / blog posts should help any beginner ( like me ) to gain fair bit of knowledge on python as we move along more complex codes within data science.

Leave a comment if you really enjoyed this crash course series.

Deviation : PCI to Python

The first chapter of PCI fascinates you on the real life examples of analytics used across retail, social and other sectors. You will be able to complete this chapter at ease. The second chapter takes a dive into recommendations & rankings which involves statistics and whole lot of python code.

Toby has explained Eucledian and Pearson score in the most easy way possible to his audience, you will be able to grasp quite a lot of knowledge from it – but then comes the challenging part. If you really want to get a feel of the working code behind these methods, the book dives into python.

I tried replicating the code into my Python 2 and tried to understand how the python code/algorithm to replicate a recommendation technique is built. The success rate if you know python in and out is 100 %, but someone like me who has basic python knowledge ( acquired from the web ) and programming skills, I am deviating in understanding the art of using python for data science. My go to options after lot of research and discussion is to sign up for datacamp :

Datacamp Module : “Intro to python for data science ”

I completed the first free module for python in about 5 hours and was able to get a good grasp of how python works, at the end of the first module ( 4 chapters ) they give you an intro of the NumPy library which is when you feel relieved and satisfied just because you touched upon the commonly used package by data scientists.

I would strongly recommend this course for all beginners of the data science stream. I will be blogging about concepts I have learnt in python in the upcoming blog posts to help the community.

Tip : Register and complete a free course in datacamp to avail minimum 40% – 50% off on all their courses for a year. Do not buy the courses after you immidiately sign up, you would end up paying about 130 USD ( close to 8500 INR ) more.

Python : Introduction To NumPy

Num Pi or Num P as it is commonly referred to is a Linear Algebra library for python. Almost all of the libraries in the PyData ecosystem reply on NumPy as one of their main building blocks. NumPy is incredibly fast.

The NumPy library can be installed using pip install command. In case you are new to installing libraries in python, I would recommend you to visit this link to get a deeper understanding on how to install libraries in python.

  • NumPy arrays will be widely used while working with data.
  • NumPy arrays essential come in two flavors : vectors and matrices.
  • NumPy Vectors are strictly 1 dimensional arrays and matrices 2 dimensional.
  • A matrix however can have just one row or just one column.

This should be sufficient for you to get started with NumPy. Let’s get started with using NumPy arrays in python using jupyter notebook.