How to use Pandas in Python
Tags: python, database, beginners
Published: 2019-08-29 14:21:00

<h2>What is Pandas? </h2>
Pandas is a simple yet powerful library used for data manipulation and analysis.
The name Pandas is derived from the word ‘Panel Data’ so not the pandas animal 

A term for multidimensional structured data sets. it’s just a cute name to a super-useful Python library!. Pandas runs on top of numpy. <i>Ok let us take a little decoy and talk about numpy. </li>

<code> <h3>What is Numpy?</h3>

<b>(Numpy)</b> Numerical Python. It is fast. It can crunch numbers way better than a python list or loops. 
NumPy arrays are the basis of all computations performed by the NumPy library. They are simple Python lists with a few additional properties. </code>

<h3>Makes sense? </h3>

<h3>Now Back to Pandas.</h3>
Pandas is quite a game changer when it comes to analyzing data with Python and it is one of the most preferred and widely used tools in data munging/wrangling if not THE most used one. Pandas was created by Wes McKinney in 2015 and has since seen an increased interest in people gravitating to Python for Data mining, and manipulation. 

<h3>Features of Pandas:</h3>
<ul>
<li>Series object and Dataframe </li>
<li>Handling of missing data</li>
<li>Data alignment </li>
<li>Group by functionality </li>
<li>Slicing, Indexing and Sub setting</li>
<li>Merging and Joining</li>
<li>Reshaping</li>
<li>Hierarchical labeling of axes</li>
<li>Robust Input/Output tool</li>
<li>Time series-specific functionality</li>
</ul>

<h3>Why use Pandas and not just stick with Numpy? </h3>
<table>
<tr> <td><h4>PANDAS</h4>
<td><h4>NUMPY </h4>
<tr><td>
Pandas performs better than Numpy for 500k rows or more
<td>Performs better for 50k rows or less
<tr> <td>
Pandas provides rich time series functionality, data alignment, friendly statistics, group by, merge and join methods, and lots of other conveniences
<td> NumPy by itself is a fairly low-level tool, and will be very much similar to using MATLAB
</tr></td></table>

<h3>Let us get to the practicals. How do we work with Pandas?</h3>

When you want to use Pandas for data analysis, you’ll usually use it in one of three different ways:
<ul>
<li>Convert a Python’s list, dictionary or Numpy array to a Pandas data frame</li>
<li>Open a local file using Pandas, usually a CSV file, but could also be a delimited text file (like TSV), Excel, etc </li>
<li>Open a remote file or database like a CSV or a JSONon a website through a URL or read from a SQL table/database</li>

</ul>

Ok, so how do we use it. I suggest work with the Anaconda Python Distribution. 
https://www.anaconda.com/

Anaconda is popular because it brings many of the tools used in data science and machine learning with just one install, so it’s great for having short and simple setup. Also comes with Numby, Jupyter Notebook, Pandas, and Python 3 installed.

I use Jupyter Notebook as my preferred Text Editor for Data Science. I still love Visual Studio Code, just that with Data Science you can't help but fall in love with Jupyter and the anaconda family. 

Datasets in pandas are either One dimensional or Multi dimensional 

<table> <tr><td>
One Dimensional
<td>Two dimensional
<td>Three dimensional
<tr><td>Series object
<td>Dataframe
<td>Panel Data
</tr></td></table>

<b>Let us work with Series object first. It is a one-dimensional labelled array</b>
 


To use pandas, you have to first import it. 

<code>import pandas as pd </code>
You need to have data before you can do anything with it. 
So let us create a python list. 

<code> data = [1, 2, 3, 4]  </code> # creating a python list 

<code>series1 = pd.Series(data) </code> #To convert this list into a dataframe 
<code> series1 </code> To print out the result. Use Shift + Enter or 'Run' button in your jupyter notebook to run your code. 

<h3>How to create a DataFrame using a list.</h3>
<code> general = ['Eddy', 'Bob', 'Linda', 'Ella'] </code> #Python list
<code>generald = pd.DataFrame(general) <code> #creating the dataframe. pd.DataFrame not pd.dataframe. 
<h3><code>general <code> # print result </h3> 

<strong>Ok, i need to go back to work, paused to put this together. Hopefully this was helpful. Let me know if you have any questions or comments.  </strong>

Enjoy the rest of your week