Site icon Python GUI

Powerful Data Analysis And Manipulation Using Pandas Library In A Delphi Windows App

Are you looking for powerful tools to analyze and manipulate structured data, and build a nice GUI for them? You can build fast, expressive, insightful, and scalable data analysis tools easily by combining pandas and Python4Delphi library, inside Delphi and C++Builder.

pandas is a Python package that provides fast, flexible, and expressive data structures designed to work with structured (tabular, multidimensional, potentially heterogeneous) and time-series data easily and intuitively.

pandas aim 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 on its way toward this goal.

 

10+ Amazing pandas Examples inside the Delphi Windows GUI App

This post will guide you on how to run various data analysis and manipulation examples using the pandas library and using Python for Delphi to display it in the Delphi Windows GUI app.

First, open and run our Python GUI using project Demo01 from Python4Delphi with RAD Studio. Then insert the script into the lower Memo, click the Execute button, and get the result in the upper Memo. You can find the Demo01 source on GitHub. The behind the scene details of how Delphi manages to run your Python code in this amazing Python GUI can be found at this link.

These examples will cover almost various functions and methods you are most likely to use in a typical data analysis process. Let’s run them all in our Python4Delphi Demo01 GUI:

1. Reading the CSV file into a pandas dataframe

[crayon-6606ae8977768219897038/]

 

2. Check the shape or dimension of the dataset

[crayon-6606ae8977772726241102/]

 

3. See the column labels of the DataFrame

[crayon-6606ae8977774216468546/]

 

4. Dropping columns

We want to remove 4 columns: ‘RowNumber‘, ‘CustomerId‘, ‘Surname‘, and  ‘CreditScore‘. The axis parameter is set as 1 to drop columns and 0 for rows. The inplace parameter is set as True to save the changes:

[crayon-6606ae8977776710091973/]

We dropped 4 columns so the number of columns reduced to 10 from 14.

 

5. Select particular columns while reading

We want to read only specific columns: ‘Gender‘, ‘Age‘, ‘Tenure‘, and ‘Balance‘:

[crayon-6606ae8977778405262594/]

 

6. Reading a part of the dataframe (from the first n number of the rows)

We want to read the first 5000 rows of the CSV file:

[crayon-6606ae8977783999927896/]

 

7. Select rows from the end of the file

We can also select rows from the end of the file by using the skiprows parameter. skiprows=5000 means that we will skip the first 5000 rows while reading the csv file:

[crayon-6606ae8977785031742014/]

 

8. Draw a small sample to work

We can either use the n parameter or frac parameter to determine the sample size.

[crayon-6606ae897778a677349130/]

[crayon-6606ae897778c962708240/]

 

9. Checking the missing values

Using the isna with the sum function, we can see the number of missing values in each column:

[crayon-6606ae897778e114629962/]

 

10. Adding missing values using loc and iloc

The “loc” and “iloc” will select rows and columns based on index or label.

[crayon-6606ae8977793870499689/]

 

11. Fill the missing values

[crayon-6606ae8977795110442304/]
[crayon-6606ae8977797595065704/]

 

Congratulations, now you have learned how to run various data analysis and manipulation examples using the pandas library and using Python for Delphi to display it in the Delphi Windows GUI app!

Check out the pandas library for Python and use it in your projects: https://pypi.org/project/pandas/ and

Check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi: https://github.com/pyscripter/python4delphi

References & further readings

[1] Hakim, M. A. (2022). Build The Ultimate GUI For Pandas To Perform Complex Data Analysis. Embarcadero Blogs. blogs.embarcadero.com/ultimate-guide-for-building-gui-for-pandas-to-perform-complex-data-analysis

[2] Yıldırım, S. (2020). 30 Examples to Master Pandas. Towards Data Science. towardsdatascience.com/30-examples-to-master-pandas-f8a2da751fa4

Exit mobile version