Pandas is one of the most powerful libraries for data analysis and is the most popular Python library, with growing usage. Before we get into the details of how to actually import Pandas, you need to remember that you will need Python successfully installed on your laptop or server. There are many ways of achieving this, but for the purposes of this post, we’re going to assume that you’ve followed through with this. For those of you who are Mac OSx users, this shouldn’t be a problem at all as Python is already pre-installed and is accessible via the command line prompt.
By far the fastest path to installing pandas is by using the Anaconda distribution. Anaconda is an open-source data analysis, science, and machine learning grouping of libraries that enables quick installation and integration.
Once you have Anaconda installed, available through a UI download online, you can apply a simple prompt into the command line to install pandas.
conda install pandas
From here, you’ll need to open your python editor (Spyder, PyCharm, etc.) or utilize a Jupyter Notebook to actually be able to enter the commands found below.
So, what’s the magic command we’re looking to ensure works?
import pandas as pd
In this statement, we’re importing the Pandas library with an alias, or variable name of pd. We could just as simply right import pandas, however, each time we’d write pandas.function() to access some part of the Pandas library, which contains many functions. We in this case simply use pd as a shorthand to access pandas when necessary.
In the last section we covered importing the entire Python library, however, sometimes we only want to import very specific functions to perform our data analysis.
The below two examples shows how this can be done for individual or multiple functions. The first of these shows that when we declare from pandas we can import the two basic functions of DataFrame and Series used for populating data into Pandas.
from pandas import DataFrame, Series
The second function shows how we can access nested functions which are within the sub-library of Pandas. Here we import the json_normalize function from the pandas.io.json class. We can think of this as our directory within the python library.
from pandas.io.json import json_normalize
All datasets have one obvious thing in common, information, but this information is easy and…
Use Pandas Series or DataFrames to make your data life easier In this article, we…