Bria  Nolan

Bria Nolan


An Introduction to Pandas

Key methods to understanding and utilizing pandas

I figure since you have found yourself navigating to this page that you probably have a good amount of data that you are looking to analyze, and you may possibly be wondering the best and most efficient way to answer some of your questions about your data. The answer to your questions can be found with the use of the Pandas package.

How to access Pandas

Due to the popularity of Pandas it has its own conventional abbreviation, so anytime you are importing pandas into python, use the nomenclature below:

import pandas as pd

Primary Use of Pandas package is the DataFrame

The pandas API defines a pandas dataframe as:

Two-dimensional, size-mutable, potentially heterogeneous tabular data. Data structure also contains labeled axes (rows and columns). Arithmetic operations align on both row and column labels. Can be thought of as a dict-like container for Series objects. The primary pandas data structure.

Basically, all that means is that you have data contained in the format to what you see below. Data found in rows and columns:

Image for post

Example dataframe with labels for data, rows and columns. Dataset from

DataFrames are extremely useful because they provide an efficient way to visualize data and then manipulate it the way you want it to be. The rows can be easily referenced by the index which are the numbers on the far left of the dataframe. The index will be the corresponding row’s number starting at zero, unless you specify names to each row. The columns can also be easily referenced by the column name such as “Track Name” or by their position in the dataframe. We will talk in more detail about referencing rows and columns later in this article.

Creation Time!

There are several ways to create a pandas dataframe:

  1. Import data from a .csv file (or other file type e.g. Excel, SQL database)
  2. from a list
  3. from a dictionary
  4. from a numpy array
  5. many, many more!

In general, you will mainly be putting data from a .csv file, or some type of data source into a pandas dataframe and not making it from scratch since that would take an insanely long time to do depending on the amount of data you have. Here is a quick, simple example from a python dictionary:

import pandas as pd
dict1 = {'Exercises': ['Running','Walking','Cycling'],
         'Mileage': [250, 1000, 550]}
df = pd.DataFrame(dict1)


Image for post

Basic dataframe made from code above

The dictionary keys (‘Exercises’ and ‘Mileage’) become the corresponding column headers. The values in the dictionary being the lists in this example became the individual data points in the dataframe. The order that the lists are in matters since Running will be placed in first since it is first in the ‘Exercises’ list and 250 will be placed in first in the second column since it is first in the ‘Mileage’ list. Also, you will notice that since I did not specify labels for the index of the dataframe it automatically was labelled 0,1, and 2.

However, like I said before the most likely way that you will be creating a pandas dataframe is from a csv or other type of file that you will import in to analyze the data. This is easily completed with just the following:

df = pd.read_csv("file_location.../file_name.csv")

pd.read_csv() is an extremely strong and versatile method and will be extremely useful depending on how you are looking to import your data. If your csv file already comes with headers or an index, you can specify this while importing and make you life so much easier. In order to understand the full ability of pd.read_csv() I suggest you look at the pandas API here.

First things first

Now you have this huge dataset ready to analyze, you have got to take a look at it and see what it looks like. As a person who is analyzing this data, you first have to become comfortable with the dataset, and really get to know what is going on in the dataset. There are four methods that I love to use in order to get to know my data and which pandas makes super easy.

  1. .head() & .tail()
  2. .info()
  3. .describe()
  4. .sample()

The line above is the line that I have in the picture at the top of the page. It with display the first 5 lines of the dataframe and each of the columns to give you an easy summary of what the data looks like. You can also specify a certain number of rows inside the () of the method to show more rows if your heart so desires.

Image for post

.head() method on song data from Spotify dataset

.tail() is the same just displaying the last 5 lines.


Image for post

.tail() method on song data from Spotify dataset

From these two quick methods, I have a general idea or the column names and just what the data looks like just from a small sample of the dataset. These methods are also really useful especially given a dataset such as the Spotify dataset working with over 3 million rows, you can easily display the dataset and get a quick idea, and it won’t take your computer a long time to display the data.

.info() is also useful in that it shows me a succinct list of all of the columns, their datatypes, and whether you have any null datapoints or not., null_counts=True)

Image for post

.info() method on song data from Spotify dataset

If you have completely integer or float columns (i.e. ‘Position’, ‘Streams’), then .describe() can be a useful method to understand more about your dataset as it will show many descriptive statistics about those columns.


Image for post

.describe() method on song data from Spotify dataset. Notice that only ‘Position’ and ‘Streams’ columns are shown since they were the only two integer columns, the other columns are strings and do not have descriptive stats.

Lastly, .sample() will allow you to randomly sample your dataframe and see if any manipulation that you made has incorrectly changed something in your dataset, and can also be great when first exploring your dataset just to get an idea of what the dataset contains exactly that was not already shown in the previous methods.


Image for post

.sample() method on song data from Spotify dataset.

I use each of these methods consistently while exploring and preparing my datasets for analysis. Anytime I change the data in a column, change a column name, or add/delete a row/column I will then make sure it all changed the way I wanted it to by quickly running at least some of the previous 5 methods.

#pandas #python #data-science #data-analytics #developer

What is GEEK

Buddha Community

An Introduction to Pandas

Udit Vashisht


Python Pandas Objects - Pandas Series and Pandas Dataframe

In this post, we will learn about pandas’ data structures/objects. Pandas provide two type of data structures:-

Pandas Series

Pandas Series is a one dimensional indexed data, which can hold datatypes like integer, string, boolean, float, python object etc. A Pandas Series can hold only one data type at a time. The axis label of the data is called the index of the series. The labels need not to be unique but must be a hashable type. The index of the series can be integer, string and even time-series data. In general, Pandas Series is nothing but a column of an excel sheet with row index being the index of the series.

Pandas Dataframe

Pandas dataframe is a primary data structure of pandas. Pandas dataframe is a two-dimensional size mutable array with both flexible row indices and flexible column names. In general, it is just like an excel sheet or SQL table. It can also be seen as a python’s dict-like container for series objects.

#python #python-pandas #pandas-dataframe #pandas-series #pandas-tutorial

Oleta  Becker

Oleta Becker


Pandas in Python

Pandas is used for data manipulation, analysis and cleaning.

What are Data Frames and Series?

Dataframe is a two dimensional, size mutable, potentially heterogeneous tabular data.

It contains rows and columns, arithmetic operations can be applied on both rows and columns.

Series is a one dimensional label array capable of holding data of any type. It can be integer, float, string, python objects etc. Panda series is nothing but a column in an excel sheet.

How to create dataframe and series?

s = pd.Series([1,2,3,4,56,np.nan,7,8,90])


Image for post

How to create a dataframe by passing a numpy array?

  1. d= pd.date_range(‘20200809’,periods=15)
  2. print(d)
  3. df = pd.DataFrame(np.random.randn(15,4), index= d, columns = [‘A’,’B’,’C’,’D’])
  4. print(df)

#pandas-series #pandas #pandas-in-python #pandas-dataframe #python

Macey  Kling

Macey Kling


Introduction to Pandas for Data Science -part 01


ata science is the process of deriving knowledge and insights from a huge and diverse set of data through organizing, processing and analysing the data. It involves many different disciplines like mathematical and statistical modelling, extracting data from it source and applying data visualization techniques. Often it also involves handling big data technologies to gather both structured and unstructured data.

Here are the Scenarios where Data science is used widely,

Recommendation systems

Financial Risk management

Improvement in Health Care services

Computer Vision

Efficient Management of Energy

Getting Started with Pandas

Pandas is an open-source Python Library used for high-performance data manipulation and data analysis using its powerful data structures. Python with pandas is in use in a variety of academic and commercial domains, including Finance, Economics, Statistics, Advertising, Web Analytics, and more. Using Pandas, we can accomplish five typical steps in the processing and analysis of data, regardless of the origin of data — load, organize, manipulate, model, and analyse the data.

Key Features of Pandas

Fast and efficient DataFrame object with default and customized indexing.

Tools for loading data into in-memory data objects from different file formats.

Data alignment and integrated handling of missing data.

Reshaping and pivoting of date sets.

Label-based slicing, indexing and subsetting of large data sets.

Columns from a data structure can be deleted or inserted.

Group by data for aggregation and transformations.

High performance merging and joining of data.

Time Series functionality.

Pandas provide essential data structures like series, dataframes, and panels which help in manipulating data sets and time series.

These data structures are built on top of Numpy array, making them fast and efficient.

Pandas possess the power to perform various tasks. Whether it is computing tasks like finding the mean, median and mode of data, or a task of handling large CSV files and manipulating the contents according to our will, Pandas can do it all. In short, to master data science, you must be skillful in Pandas.

Let’s start our Python Pandas tutorial with the methods for installing Pandas.

Just head over to ,

#pandas-dataframe #python #pandas #python-for-datascience #introduction


In my last post, I mentioned the groupby technique  in Pandas library. After creating a groupby object, it is limited to make calculations on grouped data using groupby’s own functions. For example, in the last lesson, we were able to use a few functions such as mean or sum on the object we created with groupby. But with the aggregate () method, we can use both the functions we have written and the methods used with groupby. I will show how to work with groupby in this post.

#pandas-groupby #python-pandas #pandas #data-preprocessing #pandas-tutorial


Pandas is a great library for data preprocessing. Pandas often uses libraries such as NumPy and SciPy for numerical computations and Matplotlib to visualize data. Pandas has methods similar to the methods in NumPy. While NumPy works with the same data types, Pandas can work with different data types.

A data set written in Excel or SQL table data can be easily analyzed with pandas.

Pandas module is an open-source library since 2010. Pandas is constantly updated by developers around the world.

In summary, I will explain the following topics in this post:

  • How to install Pandas?
  • Series data structure
  • Working with Series
  • DataFrame data structure

Before starting the topic, our Medium page includes posts on data science, artificial intelligence, machine learning, and deep learning. Please don’t forget to follow us on Medium 🌱 to see these posts and the latest posts.

Let’s get started.

#data-science #pandas-dataframe #pandas-series #pandas #machine-learning