Write a Python program to remove a certain length substring from a given string

Prasad Naik
Updated on 25-Mar-2026 17:52:26

262 Views

We need to write a Python program that removes a specific substring from a given string. Python provides several methods to accomplish this task efficiently. Algorithm Step 1: Define a string. Step 2: Use the replace() function to remove the substring from the given string. Step 3: Display the modified string. Using replace() Method The most straightforward approach is using the built-in replace() method to replace the unwanted substring with an empty string ? original_string = "C++ is a object oriented programming language" modified_string = original_string.replace("object oriented", "") print("Original:", original_string) print("Modified:", modified_string) ... Read More

Print dates of today, yesterday and tomorrow using Numpy

Prasad Naik
Updated on 25-Mar-2026 17:52:09

572 Views

NumPy provides datetime functionality through the datetime64 data type, allowing you to easily work with dates. You can calculate today's, yesterday's, and tomorrow's dates using np.datetime64() and np.timedelta64() functions. Understanding DateTime64 The datetime64 function creates date objects, while timedelta64 represents time differences. The 'D' parameter specifies the unit as days − import numpy as np # Get today's date today = np.datetime64('today', 'D') print("Today's Date:", today) Today's Date: 2024-01-15 Calculating Yesterday and Tomorrow You can add or subtract timedelta64 objects to get past or future dates ? ... Read More

How to make several plots on a single page using matplotlib in Python?

Rishikesh Kumar Rishi
Updated on 25-Mar-2026 17:51:53

512 Views

Matplotlib provides several methods to create multiple plots on a single page. You can use subplots() to create a grid of subplots or subplot() to add plots one by one. This is useful for comparing different datasets or showing related visualizations together. Method 1: Using subplots() with Multiple Axes The subplots() function creates a figure with multiple subplot areas in a grid layout − import matplotlib.pyplot as plt import numpy as np # Sample data x = np.linspace(0, 10, 100) y1 = np.sin(x) y2 = np.cos(x) y3 = np.tan(x) y4 = np.log(x + 1) ... Read More

Scatter plot and Color mapping in Python

Rishikesh Kumar Rishi
Updated on 25-Mar-2026 17:51:25

874 Views

We can create scatter plots with color mapping using Matplotlib's scatter() method. This technique allows us to visualize an additional dimension of data through color variations, making patterns and relationships more apparent. Basic Scatter Plot with Color Mapping Here's how to create a scatter plot where each point has a different color based on its position in the dataset − import matplotlib.pyplot as plt import numpy as np # Generate random data points x = np.random.rand(100) y = np.random.rand(100) # Create scatter plot with color mapping colors = range(100) plt.scatter(x, y, c=colors, cmap='viridis') plt.colorbar() ... Read More

How to reset index in Pandas dataframe?

Prasad Naik
Updated on 25-Mar-2026 17:51:04

480 Views

In Pandas, the index serves as row labels for a DataFrame. Sometimes you need to reset the index back to the default integer sequence (0, 1, 2...) or convert a custom index into a regular column. The reset_index() method provides this functionality. Basic reset_index() Usage Let's start with a simple example showing how to reset a DataFrame's index ? import pandas as pd # Create DataFrame with default index data = {'Name': ["Allen", "Jack", "Mark", "Vishal"], 'Marks': [85, 92, 99, 87]} df = pd.DataFrame(data) print("Original DataFrame:") ... Read More

How to plot two dotted lines and set marker using Matplotlib?

Prasad Naik
Updated on 25-Mar-2026 17:50:44

2K+ Views

In this article, we will learn how to plot two dotted lines with custom markers using Matplotlib. Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python. Prerequisites First, we need to import the matplotlib.pyplot module ? import matplotlib.pyplot as plt Pyplot is a collection of command-style functions that make matplotlib work like MATLAB, providing an easy interface for plotting. Basic Example with Dotted Lines Let's start with a simple example plotting two dotted lines ? import matplotlib.pyplot as plt # Define coordinates for two ... Read More

How to draw different shapes using the Python Turtle library?

Prasad Naik
Updated on 25-Mar-2026 17:50:20

4K+ Views

The Python Turtle library provides a fun way to create graphics by controlling a turtle that moves around a drawing canvas. In this tutorial, we'll learn how to draw different geometric shapes including squares, rectangles, circles, and hexagons using turtle graphics. What is Turtle Graphics? Turtle graphics is a drawing method where you control a "turtle" that moves around the screen, leaving a trail behind it. You can command the turtle to move forward, turn left or right, and lift or lower its pen to create various shapes and patterns. Drawing a Square A square has ... Read More

Python program to compare two Pandas series

Prasad Naik
Updated on 25-Mar-2026 17:49:54

691 Views

In this program, we will declare two Pandas series and compare their elements using comparison operators. Pandas provides element-wise comparison operations that return boolean Series objects. Before we solve the problem, we need to import the Pandas library into our local IDE. This can be done by installing Pandas on our local machine. The command for installing Pandas is − pip install pandas Input Data We will use two sample series for comparison ? Series1 = [2, 4, 6, 8, 10] Series2 = [1, 3, 5, 7, 9] Algorithm ... Read More

How to maximize a plt.show() window using Python?

Rishikesh Kumar Rishi
Updated on 25-Mar-2026 17:49:39

5K+ Views

To maximize a matplotlib plot window, you can use the figure manager's built-in methods. The most common approach is using plt.get_current_fig_manager() along with full_screen_toggle() or window.state() methods. Method 1: Using full_screen_toggle() This method toggles the window to full screen mode ? import matplotlib.pyplot as plt plt.subplot(1, 1, 1) plt.pie([1, 2, 3], labels=['A', 'B', 'C']) plt.title('Sample Pie Chart') mng = plt.get_current_fig_manager() mng.full_screen_toggle() plt.show() Method 2: Using window.state() (Tkinter backend) For Tkinter backend, you can maximize the window using the state method ? import matplotlib.pyplot as plt plt.subplot(1, 1, 1) ... Read More

How to make two plots side-by-side using Python?

Rishikesh Kumar Rishi
Updated on 25-Mar-2026 17:49:21

32K+ Views

When creating data visualizations, you often need to display multiple plots side-by-side for comparison. Python's Matplotlib provides the subplot() method to divide a figure into multiple sections and place plots in specific positions. Using plt.subplot() Method The subplot(nrows, ncols, index) method splits a figure into a grid of nrows × ncols sections. The index parameter specifies which section to use for the current plot ? from matplotlib import pyplot as plt import numpy as np # Create sample data x_points = np.array([2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) y1_points = np.array([12, 14, ... Read More

Advertisements