Programming Articles

Page 123 of 2547

Python Program to Count number of lines present in the file

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 27-Mar-2026 10K+ Views

In Python, we can count the number of lines in a file using several built-in functions and methods. This is useful for analyzing file contents or processing large text files. We'll explore different approaches to count lines efficiently. Syntax The basic syntax for opening a file in Python is ? with open("filename.txt", mode) as file: # file operations The open() function accepts two main parameters ? filename.txt ? The name of the file to open. mode ? Determines how the file is opened ('r' for reading, 'w' for ...

Read More

Python program to delete prefix substring from the given string

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 27-Mar-2026 362 Views

In this article, we will learn how to create a Python program to delete prefix substrings from a given string. A prefix is a group of characters that are added to the beginning of a string. When working with text data, you often need to remove common prefixes to clean or process the data efficiently. For example, if the given string is "My shirt color is Red" and we want to delete the prefix "My", the final output becomes " shirt color is Red". Methods for Removing Prefixes Method 1: Using startswith() and Slicing The startswith() ...

Read More

Python program to delete suffix from the given string

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 27-Mar-2026 3K+ Views

In Python, we have several built-in string methods like endswith(), rstrip(), and replace() that can be used to delete suffixes from strings. A suffix is a group of characters at the end of a string that we want to remove. For example, removing "NING" from "BRIGHTNING" gives us "BRIGHT". Common Methods for Suffix Removal endswith() Method This method checks if a string ends with a specified suffix and returns True or False ? text = "programming" print(text.endswith("ming")) # True print(text.endswith("code")) # False True False rstrip() Method This ...

Read More

Analyzing Decision Tree and K-means Clustering using Iris dataset

Priya Mishra
Priya Mishra
Updated on 27-Mar-2026 878 Views

Decision trees and K-means clustering are fundamental machine learning algorithms for pattern discovery and classification. This article demonstrates how to apply both techniques to the famous Iris dataset, comparing their performance and visualizing the results. Iris Dataset Overview The Iris dataset, introduced by Ronald Fisher in 1936, contains 150 samples of iris flowers from three species: Iris setosa, Iris versicolor, and Iris virginica. Each sample has four features measured in centimeters ? Sepal Length Sepal Width Petal Length Petal Width This dataset is ideal for testing classification and clustering algorithms due to its ...

Read More

How to Alter an SQLite Table using Python?

Priya Mishra
Priya Mishra
Updated on 27-Mar-2026 2K+ Views

Altering an SQLite table is a common task when working with databases and can be easily done using Python. SQLite is a lightweight, file-based database that doesn't require a separate server, making it perfect for small to medium applications. In this article, we'll explore how to alter an SQLite table using Python's built-in sqlite3 module. We'll cover adding columns, modifying existing tables, and provide complete working examples. What is SQLite? SQLite is an open-source, serverless database engine that stores data in local files. Python's sqlite3 module comes pre-installed and provides a simple interface for working with SQLite ...

Read More

How to add timestamp to excel file in Python?

Priya Mishra
Priya Mishra
Updated on 27-Mar-2026 3K+ Views

If you're working with data in Python and need to track changes or monitor updates, adding a timestamp to your Excel files can be a game-changer. When we are working with large quantities of data, Excel can be used to analyze when specific modifications or events occurred. This can be accomplished by including a timestamp in the Excel file which will tell when a particular modification has been done to a cell. The modules required for adding timestamps to Excel files are openpyxl and datetime. In this article, we will see how to add timestamps and the modules used ...

Read More

How to add text in a heatmap cell annotations using seaborn in Python?

Priya Mishra
Priya Mishra
Updated on 27-Mar-2026 2K+ Views

Heatmaps are powerful data visualization tools that display the magnitude of phenomena using color intensity in a two-dimensional format. Seaborn provides excellent functionality for creating heatmaps and customizing cell annotations with text labels or numerical values to enhance data understanding. Understanding Heatmaps A heatmap visualizes data through colors in a matrix format, where different color intensities represent varying data values. The visual representation makes it easy to identify patterns, correlations, and outliers in datasets. Basic Heatmap Syntax The sns.heatmap() function provides comprehensive options for customization − sns.heatmap(data, *, annot=None, fmt='.2g', annot_kws=None, ...

Read More

How to add Regression Line Per Group with Seaborn in Python?

Priya Mishra
Priya Mishra
Updated on 27-Mar-2026 860 Views

One of the most useful tools provided by Seaborn is the ability to add regression lines to scatterplots. Regression lines help analyze relationships between two variables and identify trends in data, especially when comparing different groups within your dataset. In this article, we will learn how to add regression lines per group with Seaborn in Python using lmplot() and regplot() functions. These methods allow you to visualize relationships separately for different categories in your data. What is a Regression Line? A regression line shows the best-fit trend through a set of data points. It represents the linear ...

Read More

How to Add Outline or Edge Color to Histogram in Seaborn?

Priya Mishra
Priya Mishra
Updated on 27-Mar-2026 923 Views

While Seaborn makes it easy to create histograms with a variety of styles and options, by default, histograms do not have an outline or edge color. Adding an outline or edge color can help make the plot more visually appealing and easier to interpret. In this article, we will explore how to add an outline or edge color to a histogram in Seaborn using histplot() and the deprecated distplot() method. What is a Histogram? Histograms are graphical tools that show how a set of continuous data is distributed. Seaborn helps us plot both the histogram bars and a ...

Read More

How to add one row in an existing Pandas DataFrame?

Priya Mishra
Priya Mishra
Updated on 27-Mar-2026 3K+ Views

While working with data using Pandas in Python, adding a new row to an existing DataFrame is a common task that can be performed using various methods. Pandas is a popular data manipulation library that provides multiple functionalities for data analysis. In this article, we will discuss how to add one row in an existing Pandas DataFrame using different methods. Sample DataFrame Before we add a new row to the Pandas DataFrame, let's first create a sample DataFrame that we will use throughout the article. We will create a DataFrame with three columns: "Name", "Gender", and "Age". ...

Read More
Showing 1221–1230 of 25,466 articles
« Prev 1 121 122 123 124 125 2547 Next »
Advertisements