Python Panda library
LOAD data
dataset_dict = { ‘Outlook’: [‘sunny’, ‘sunny’, ‘overcast’, ‘rainy’, ‘rainy’, ‘rainy’, ‘overcast’, ‘sunny’, ‘sunny’, ‘rainy’, ‘sunny’, ‘overcast’, ‘overcast’, ‘rainy’, ‘sunny’, ‘overcast’, ‘rainy’, ‘sunny’, ‘sunny’, ‘rainy’, ‘overcast’, ‘rainy’, ‘sunny’, ‘overcast’, ‘sunny’, ‘overcast’, ‘rainy’, ‘overcast’],
‘Temperature’: [85.0, 80.0, 83.0, 70.0, 68.0, 65.0, 64.0, 72.0, 69.0, 75.0, 75.0, 72.0, 81.0, 71.0, 81.0, 74.0, 76.0, 78.0, 82.0, 67.0, 85.0, 73.0, 88.0, 77.0, 79.0, 80.0, 66.0, 84.0],
‘Humidity’: [85.0, 90.0, 78.0, 96.0, 80.0, 70.0, 65.0, 95.0, 70.0, 80.0, 70.0, 90.0, 75.0, 80.0, 88.0, 92.0, 85.0, 75.0, 92.0, 90.0, 85.0, 88.0, 65.0, 70.0, 60.0, 95.0, 70.0, 78.0],
‘Wind’: [False, True, False, False, False, True, True, False, False, False, True, True, False, True, True, False, False, True, False, True, True, False, True, False, False, True, False, False],
‘Play’: [‘No’, ‘No’, ‘Yes’, ‘Yes’, ‘Yes’, ‘No’, ‘Yes’, ‘No’, ‘Yes’, ‘Yes’, ‘Yes’, ‘Yes’, ‘Yes’, ‘No’, ‘No’, ‘Yes’, ‘Yes’, ‘No’, ‘No’, ‘No’, ‘Yes’, ‘Yes’, ‘Yes’, ‘Yes’, ‘Yes’, ‘Yes’, ‘No’, ‘Yes’]
}
df = pd.DataFrame(dataset_dict)
Prepare data
df = pd.get_dummies(df, columns=[‘Outlook’], prefix=”, prefix_sep=”, dtype=int)
df[‘Wind’] = df[‘Wind’].astype(int)
df[‘Play’] = (df[‘Play’] == ‘Yes’).astype(int)
Split data
X, y = df.drop(columns=’Play’), df[‘Play’]
X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.5, shuffle=False)
Train model
dt_clf = DecisionTreeClassifier(
max_depth=None, # Maximum depth of the tree
min_samples_split=2, # Minimum number of samples required to split an internal node
min_samples_leaf=1, # Minimum number of samples required to be at a leaf node
criterion=’gini’ # Function to measure the quality of a split
)
dt_clf.fit(X_train, y_train)
Make predictions
y_pred = dt_clf.predict(X_test)
Evaluate model
print(f”Accuracy: {accuracy_score(y_test, y_pred)}”)
Visualize tree
plt.figure(figsize=(20, 10))
plot_tree(dt_clf, filled=True, feature_names=X.columns,
class_names=[‘Not Play’, ‘Play’], impurity=False)
plt.show()
Python Panda library
The Python Pandas library is an open-source data analysis and manipulation toolkit widely used in data science, machine learning, and analytics. It provides core structures—DataFrame and Series—for managing tabular and time-series data, enabling users to efficiently clean, manipulate, analyze, and visualize data. Pandas makes it easy to handle missing values, filter rows, reshape datasets, merge and join multiple data sources, and generate summary statistics[1][3][4][5].
Key Features
- Data Structures: Uses DataFrame (tabular data) and Series (1D data) for flexible data operations.
- Data Cleaning: Handles missing data, duplicates, and irrelevant entries, enabling accurate analysis[1][4].
- Integration: Works well with other libraries such as NumPy, Matplotlib, and Scikit-learn for machine learning and visualization[3][4].
- Efficient Manipulation: Supports sorting, grouping, aggregation, and advanced filtering of large datasets[2].
- Visualization: Integrates plotting functions for quick data visualization[1][3].
- File Handling: Reads and writes data from multiple file formats like CSV, Excel, SQL databases, and more[3][5].
Applications
- Data preprocessing for machine learning pipelines.
- Financial and statistical data analysis.
- Exploratory data analysis and reporting.
- Building features from raw data for predictive modeling[1][6].
Pandas streamlines data-related tasks in Python, making it essential for modern data science and machine learning workflows[1][3][4][5].
🐼 Pandas is a powerful open-source Python library designed for data manipulation and analysis. It’s especially popular in data science, machine learning, and statistical computing. Here’s a quick overview to get you started:
📦 What Is Pandas?
- Developed by Wes McKinney in 2008.
- Built on top of NumPy, and integrates well with libraries like Matplotlib, SciPy, and Scikit-learn.
- Ideal for working with tabular data (like spreadsheets, SQL tables) and time series data.
🧰 Key Features
- Series: One-dimensional labeled array.
- DataFrame: Two-dimensional labeled data structure (like a table).
- Data Cleaning: Handle missing data, remove duplicates, fix inconsistencies.
- Data Transformation: Merge, join, reshape, and pivot datasets.
- Group By: Powerful aggregation and transformation using split-apply-combine.
- Visualization: Works with Matplotlib and Seaborn for plotting.
- I/O Tools: Read/write from CSV, Excel, SQL, JSON, and HDF5 formats.
🚀 Getting Started
`python
Install Pandas
pip install pandas
Import Pandas
import pandas as pd
Create a simple DataFrame
data = {‘Name’: [‘Alice’, ‘Bob’], ‘Age’: [25, 30]}
df = pd.DataFrame(data)
print(df)
`
Package overview
pandas is a Python package providing fast, flexible, and expressive data structures designed to make working with “relational” or “labeled” data both easy and intuitive. It aims to be the fundamental high-level building block for doing practical, real-world data analysis in Python. Additionally, it has the broader goal of becoming the most powerful and flexible open source data analysis/manipulation tool available in any language. It is already well on its way toward this goal.
pandas is well suited for many different kinds of data:
- Tabular data with heterogeneously-typed columns, as in an SQL table or Excel spreadsheet
- Ordered and unordered (not necessarily fixed-frequency) time series data.
- Arbitrary matrix data (homogeneously typed or heterogeneous) with row and column labels
- Any other form of observational / statistical data sets. The data need not be labeled at all to be placed into a pandas data structure
The two primary data structures of pandas, Series (1-dimensional) and DataFrame (2-dimensional), handle the vast majority of typical use cases in finance, statistics, social science, and many areas of engineering. For R users, DataFrame provides everything that R’s data.frame provides and much more. pandas is built on top of NumPy and is intended to integrate well within a scientific computing environment with many other 3rd party libraries.
Here are just a few of the things that pandas does well:
- Easy handling of missing data (represented as NaN) in floating point as well as non-floating point data
- Size mutability: columns can be inserted and deleted from DataFrame and higher dimensional objects
- Automatic and explicit data alignment: objects can be explicitly aligned to a set of labels, or the user can simply ignore the labels and let
Series,DataFrame, etc. automatically align the data for you in computations- Powerful, flexible group by functionality to perform split-apply-combine operations on data sets, for both aggregating and transforming data
- Make it easy to convert ragged, differently-indexed data in other Python and NumPy data structures into DataFrame objects
- Intelligent label-based slicing, fancy indexing, and subsetting of large data sets
- Intuitive merging and joining data sets
- Flexible reshaping and pivoting of data sets
- Hierarchical labeling of axes (possible to have multiple labels per tick)
- Robust IO tools for loading data from flat files (CSV and delimited), Excel files, databases, and saving / loading data from the ultrafast HDF5 format
- Time series-specific functionality: date range generation and frequency conversion, moving window statistics, date shifting, and lagging.
Many of these principles are here to address the shortcomings frequently experienced using other languages / scientific research environments. For data scientists, working with data is typically divided into multiple stages: munging and cleaning data, analyzing / modeling it, then organizing the results of the analysis into a form suitable for plotting or tabular display. pandas is the ideal tool for all of these tasks.
Some other notes
- pandas is fast. Many of the low-level algorithmic bits have been extensively tweaked in Cython code. However, as with anything else generalization usually sacrifices performance. So if you focus on one feature for your application you may be able to create a faster specialized tool.
- pandas is a dependency of statsmodels, making it an important part of the statistical computing ecosystem in Python.
- pandas has been used extensively in production in financial applications.
Data structures
| Dimensions | Name | Description |
|---|---|---|
| 1 | Series | 1D labeled homogeneously-typed array |
| 2 | DataFrame | General 2D labeled, size-mutable tabular structure with potentially heterogeneously-typed column |
Why more than one data structure?
The best way to think about the pandas data structures is as flexible containers for lower dimensional data. For example, DataFrame is a container for Series, and Series is a container for scalars. We would like to be able to insert and remove objects from these containers in a dictionary-like fashion.
Also, we would like sensible default behaviors for the common API functions which take into account the typical orientation of time series and cross-sectional data sets. When using the N-dimensional array (ndarrays) to store 2- and 3-dimensional data, a burden is placed on the user to consider the orientation of the data set when writing functions; axes are considered more or less equivalent (except when C- or Fortran-contiguousness matters for performance). In pandas, the axes are intended to lend more semantic meaning to the data; i.e., for a particular data set, there is likely to be a “right” way to orient the data. The goal, then, is to reduce the amount of mental effort required to code up data transformations in downstream functions.
For example, with tabular data (DataFrame) it is more semantically helpful to think of the index (the rows) and the columns rather than axis 0 and axis 1. Iterating through the columns of the DataFrame thus results in more readable code:
for col in df.columns:
series = df[col]
# do something with series
Mutability and copying of data
All pandas data structures are value-mutable (the values they contain can be altered) but not always size-mutable. The length of a Series cannot be changed, but, for example, columns can be inserted into a DataFrame. However, the vast majority of methods produce new objects and leave the input data untouched. In general we like to favor immutability where sensible.
Getting support
The first stop for pandas issues and ideas is the GitHub Issue Tracker. If you have a general question, pandas community experts can answer through Stack Overflow.
Community
pandas is actively supported today by a community of like-minded individuals around the world who contribute their valuable time and energy to help make open source pandas possible. Thanks to all of our contributors.
If you’re interested in contributing, please visit the contributing guide.
pandas is a NumFOCUS sponsored project. This will help ensure the success of the development of pandas as a world-class open-source project and makes it possible to donate to the project.
Project governance
The governance process that pandas project has used informally since its inception in 2008 is formalized in Project Governance documents. The documents clarify how decisions are made and how the various elements of our community interact, including the relationship between open source collaborative development and work that may be funded by for-profit or non-profit entities.
Wes McKinney is the Benevolent Dictator for Life (BDFL).
Development team
The list of the Core Team members and more detailed information can be found on the pandas website.
Institutional partners
The information about current institutional partners can be found on pandas website page.
Pandas is open-source Python library which is used for data manipulation and analysis. It consist of data structures and functions to perform efficient operations on data. It is well-suited for working with tabular data such as spreadsheets or SQL tables. It is used in data science because it works well with other important libraries. It is built on top of the NumPy library as it makes easier to manipulate and analyze. Pandas is used in other libraries such as:
- Matplotlib for plotting graphs
- SciPy for statistical analysis
- Scikit-learn for machine learning algorithms.
- It uses many functionalities provided by NumPy library.
Here is a various tasks that we can do using Pandas:
- Data Cleaning, Merging and Joining: Clean and combine data from multiple sources, handling inconsistencies and duplicates.
- Handling Missing Data: Manage missing values (NaN) in both floating and non-floating point data.
- Column Insertion and Deletion: Easily add, remove or modify columns in a DataFrame.
- Group By Operations: Use “split-apply-combine” to group and analyze data.
- Data Visualization: Create visualizations with Matplotlib and Seaborn, integrated with Pandas.
To learn Pandas from basic to advanced refer to our page: Pandas tutorial
Getting Started with Pandas
Let’s see how to start working with the Python Pandas library:
Installing Pandas
First step in working with Pandas is to ensure whether it is installed in the system or not. If not then we need to install it on our system using the pip command.
pip install pandas
For more reference, take a look at this article on installing pandas.
Importing Pandas
After the Pandas have been installed in the system we need to import the library. This module is imported using:
import pandas as pd
Note: pd is just an alias for Pandas. It’s not required but using it makes the code shorter when calling methods or properties.
Data Structures in Pandas Library
Pandas provide two data structures for manipulating data which are as follows:
1. Pandas Series
A Pandas Series is one-dimensional labeled array capable of holding data of any type (integer, string, float, Python objects etc.). The axis labels are collectively called indexes.
Pandas Series is created by loading the datasets from existing storage which can be a SQL database, a CSV file or an Excel file. It can be created from lists, dictionaries, scalar values, etc.
Example: Creating a series using the Pandas Library.import pandas as pd import numpy as np ser = pd.Series() print("Pandas Series: ", ser) data = np.array(['g', 'e', 'e', 'k', 's']) ser = pd.Series(data) print("Pandas Series:\n", ser)
Output:

2. Pandas DataFrame
Pandas DataFrame is a two-dimensional data structure with labeled axes (rows and columns). It is created by loading the datasets from existing storage which can be a SQL database, a CSV file or an Excel file. It can be created from lists, dictionaries, a list of dictionaries etc.
Example: Creating a DataFrame Using the Pandas Libraryimport pandas as pd df = pd.DataFrame() print(df) lst = ['Geeks', 'For', 'Geeks', 'is', 'portal', 'for', 'Geeks'] df = pd.DataFrame(lst) print(df)
Output:

With Pandas, we have a flexible tool to handle data efficiently whether we’re cleaning, analyzing or visualizing it for our next project.
Getting started with pandas