Kiran P

Kiran P

107 Articles Published

Articles by Kiran P

107 articles

How to select multiple DataFrame columns using regexp and datatypes

Kiran P
Kiran P
Updated on 25-Mar-2026 867 Views

A DataFrame is a two-dimensional tabular data structure with rows and columns, similar to a spreadsheet or database table. Selecting specific columns efficiently is crucial for data analysis. This article demonstrates how to select DataFrame columns using regular expressions and data types. Creating a Sample DataFrame Let's start by creating a DataFrame from a movies dataset ? import pandas as pd # Create DataFrame from CSV movies_dataset = pd.read_csv("https://raw.githubusercontent.com/sasankac/TestDataSet/master/movies_data.csv") # Display basic info print(type(movies_dataset)) print(movies_dataset.head()) budget id original_language original_title popularity release_date ...

Read More

How to create charts in excel using Python with openpyxl?

Kiran P
Kiran P
Updated on 25-Mar-2026 2K+ Views

In this tutorial, we'll create Excel charts using Python's openpyxl module. We'll build a spreadsheet with tennis players' Grand Slam titles and create a bar chart to visualize the data. What is openpyxl? The openpyxl module is a powerful Python library for working with Excel files (.xlsx). Unlike the xlrd module which is read-only, openpyxl supports both reading and writing operations, making it ideal for creating charts and manipulating Excel data. Installation First, install the openpyxl module ? pip install openpyxl Creating a Spreadsheet with Data Let's start by creating a ...

Read More

How to interpolate data values into strings in Python?

Kiran P
Kiran P
Updated on 25-Mar-2026 302 Views

We can interpolate data values into strings using various formats. We can use this to debug code, produce reports, forms, and other outputs. In this topic, we will see three ways of formatting strings and how to interpolate data values into strings. Python has three ways of formatting strings: % − old school (supported in Python 2 and 3) format() − new style (Python 2.6 and up) f-strings − newest style (Python 3.6 and up) Old Style: % Formatting The old style of string formatting has the form format_string % data. The format strings ...

Read More

How to restrict argument values using choice options in Python?

Kiran P
Kiran P
Updated on 25-Mar-2026 3K+ Views

When building command-line applications in Python, you often need to restrict user input to specific valid values. Python's argparse module provides the choices parameter to limit argument values to predefined options, preventing invalid input and improving data validation. Basic Argument Parser Without Restrictions Let's start with a simple tennis Grand Slam title tracker that accepts any integer value ? import argparse def get_args(): """Function to parse command line arguments""" parser = argparse.ArgumentParser( description='Tennis Grand Slam title tracker', ...

Read More

How to use one or more same positional arguments in Python?

Kiran P
Kiran P
Updated on 25-Mar-2026 908 Views

Python's argparse module allows you to handle multiple positional arguments of the same type using the nargs parameter. This is particularly useful when you need exactly N arguments of the same data type, like performing arithmetic operations on numbers. Using nargs for Same Type Arguments The nargs parameter specifies how many command-line arguments should be consumed. When you set nargs=2, argparse expects exactly two values of the specified type. Example: Subtracting Two Numbers Let's create a program that subtracts two integers using positional arguments − import argparse def get_args(): ...

Read More

How to plot pie-chart with a single pie highlighted with Python Matplotlib?

Kiran P
Kiran P
Updated on 25-Mar-2026 993 Views

Pie charts are one of the most popular visualization types for displaying percentages and proportions. In this tutorial, we'll learn how to create pie charts with highlighted segments using Python's Matplotlib library. Basic Pie Chart Setup First, let's install and import the required library − import matplotlib.pyplot as plt # Sample data: Tennis Grand Slam titles tennis_stats = (('Federer', 20), ('Nadal', 20), ('Djokovic', 17), ('Murray', 3)) # Extract titles and player names titles = [title for player, title in tennis_stats] players = [player for player, title in tennis_stats] print("Titles:", titles) print("Players:", players) ...

Read More

How to plot 4D scatter-plot with custom colours and cutom area size in Python Matplotlib?

Kiran P
Kiran P
Updated on 25-Mar-2026 970 Views

A 4D scatter plot in Matplotlib allows you to visualize four dimensions of data simultaneously: X and Y coordinates, point size (area), and color. This is useful for analyzing relationships between multiple variables in a single visualization. Installing Matplotlib First, install matplotlib using pip ? pip install matplotlib Basic 2D Scatter Plot Let's start with a simple 2D scatter plot using tennis player statistics ? import matplotlib.pyplot as plt # Tennis player data (name, grand slam titles) tennis_stats = (('Federer', 20), ('Nadal', 20), ('Djokovic', 17), ('Sampras', 14), ...

Read More

How to extract required data from structured strings in Python?

Kiran P
Kiran P
Updated on 25-Mar-2026 2K+ Views

When working with structured strings like log files or reports, you often need to extract specific data fields. Python provides several approaches to parse these strings efficiently when the format is known and consistent. Understanding Structured String Format Let's work with a structured report format: Report: - Time: - Player: - Titles: - Country: Here's our sample data: report = 'Report: Daily_Report - Time: 2020-10-10T12:30:59.000000 - Player: Federer - Titles: 20 - Country: Switzerland' print(report) Report: Daily_Report - Time: 2020-10-10T12:30:59.000000 - Player: Federer - ...

Read More

How to create Microsoft Word paragraphs and insert Images in Python?

Kiran P
Kiran P
Updated on 25-Mar-2026 552 Views

Creating Microsoft Word documents programmatically in Python is essential for automating report generation. The python-docx library provides a simple interface to create paragraphs, add text formatting, and insert images into Word documents. Installing python-docx First, install the required library using pip ? pip install python-docx Creating Paragraphs and Adding Text Start by creating a new document and adding paragraphs with text ? import docx # Create a new document word_doc = docx.Document() # Add a paragraph paragraph = word_doc.add_paragraph('1. Hello World, Some Sample Text Here...') run = paragraph.add_run() ...

Read More

How to Add Legends to charts in Python?

Kiran P
Kiran P
Updated on 25-Mar-2026 4K+ Views

Charts help visualize complex data effectively. When creating charts with multiple data series, legends are essential for identifying what each visual element represents. Python's matplotlib library provides flexible options for adding and customizing legends. Basic Legend Setup First, let's prepare sample data and create a basic bar chart with legends ? import matplotlib.pyplot as plt # Sample mobile sales data (in millions) mobile_brands = ['iPhone', 'Galaxy', 'Pixel'] units_sold = ( ('2016', 12, 8, 6), ('2017', 14, 10, 7), ('2018', 16, 12, 8), ...

Read More
Showing 1–10 of 107 articles
« Prev 1 2 3 4 5 11 Next »
Advertisements