Rohan Singh

Rohan Singh

143 Articles Published

Articles by Rohan Singh

Page 7 of 15

Get Random Range Average using Python

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 909 Views

Python provides several methods to generate random numbers within a specific range and calculate their average. This article explores four different approaches using the random module, NumPy library, random.choices() function, and statistics module. Algorithm The general algorithm to generate random numbers and find their average is: Generate random numbers within a specified range Store these numbers in a list or array Calculate the average of the generated numbers Display the result Method 1: Using the Random Module The random module provides a simple way to generate random numbers. We can use random.randint(a, b) ...

Read More

Python Program to Print the first letter of each word using regex

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 3K+ Views

Regular expressions (regex) in Python provide powerful pattern-matching capabilities for text manipulation. We can extract the first letter of each word using regex patterns that identify word boundaries. In this article, we will explore different approaches to print the first letter of each word using regex. Regular Expressions Overview Regular expressions are sequences of characters that define search patterns. They are widely used for text processing tasks like validation, extraction, and manipulation. Python's re module provides comprehensive regex functionality. Method 1: Using findall() with Word Boundaries The re.findall() method finds all non-overlapping matches of a pattern ...

Read More

Python Program to Determine the Unicode Code Point at a given index

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 5K+ Views

A Unicode code point is a unique number that represents a character in the Unicode standard. Unicode supports over 130, 000 characters including letters, symbols, and emojis. Python provides several methods to determine the Unicode code point at a specific index: ord() function, codecs module, unicodedata module, and array module. What is a Unicode Code Point? Every Unicode character has a unique numeric identifier called a code point. Code points are represented in hexadecimal notation with a "U+" prefix followed by a four or more digit hexadecimal number (e.g., U+0065 for 'e'). Method 1: Using ord() Function ...

Read More

Python Program to Compare two strings lexicographically

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 5K+ Views

We can compare two strings lexicographically in Python using comparison operators like , ==, =. Lexicographic comparison is the process of comparing two strings based on their alphabetical order, similar to how words are arranged in a dictionary. Algorithm A generalized algorithm to compare two strings lexicographically is as follows − Initialize two strings with the values to be compared. Compare the first character of both strings. If they are equal, move to the next character and repeat. If they are not equal, proceed to step 3. Determine which character comes first alphabetically. The string with ...

Read More

How to Save Pandas Dataframe as gzip/zip File?

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 7K+ Views

Pandas DataFrames can be saved in compressed gzip/zip format to reduce file size and improve storage efficiency. Python provides multiple approaches using gzip, zipfile modules, and built-in compression parameters in pandas methods. Method 1: Using to_csv() with Built-in Compression The simplest approach is using pandas' built-in compression parameter with to_csv() ? Saving as Gzip File import pandas as pd # Create a DataFrame data = {'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, 30, 35], 'Salary': [50000, 60000, 70000]} df ...

Read More

How to Run Python Flask App Online using Ngrok?

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 6K+ Views

Ngrok is a tool that creates a secure tunnel between your local machine and the internet. It allows developers to expose their local web server to the internet without deploying it to a remote server. Python Flask lets you create web applications locally, but with Ngrok, you can showcase them online instantly. Step 1: Install Ngrok Download Ngrok from its official website (https://ngrok.com/download) for your operating system (Windows/macOS/Linux). Extract the archive to your preferred folder location. Step 2: Create a Flask App Create a new Python file called app.py with a simple Flask application ? ...

Read More

How to run multiple Python files in a folder one after another?

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 12K+ Views

The subprocess module can be used to run multiple Python files in a folder one after another. Running multiple files sequentially is required in various situations like processing large datasets, performing complex analysis, or automating workflows. In this article, we will discuss different methods for running multiple Python files in a folder sequentially with practical examples. Method 1: Using subprocess Module The subprocess module provides a powerful way to spawn new processes and run external commands. Here's how to use it for running Python files sequentially ? Step 1: Create Sample Python Files First, let's create ...

Read More

How to rotate the X label using Pygal?

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 357 Views

Pygal is a Python library that is used to create interactive, customizable charts and graphs. We can rotate the x-axis label using the x_label_rotation attribute in the Pygal module. The rotation of the x-axis label makes the chart easier to read and comprehend when dealing with long labels or limited space. Algorithm A general algorithm for rotating the x label using pygal is given below − Import the Pygal module. Create a chart object (e.g., Bar, Line, Pie, etc.). Add data to the chart ...

Read More

How to Retrieve an Entire Row or Column of an Array in Python?

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 8K+ Views

Python provides various methods to retrieve entire rows or columns from arrays. We can use slice notation, NumPy functions, list comprehension, and for loops. In this article, we'll explore all these methods with practical examples. Using Slice Notation Slice notation extracts subsets of elements using the : notation. To retrieve entire rows or columns, we specify : for the dimension we want completely ? Syntax array_name[row_index, column_index] # For entire row: array_name[row_index, :] # For entire column: array_name[:, column_index] Example Here we create a 2D array and retrieve the second ...

Read More

How to reshape Pandas Series?

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 3K+ Views

A Pandas Series is a one-dimensional labeled array that can hold various data types. Reshaping a Series means changing its structure or format to suit different analysis needs. Python provides several methods to reshape Series data including transpose, reshape, melt, and pivot operations. Using the Transpose Attribute (.T) The transpose attribute switches rows and columns. For a Series, this operation doesn't change much since it's already one-dimensional ? import pandas as pd # Create a Series series = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd']) print("Original Series:") print(series) # Transpose the Series series_transposed ...

Read More
Showing 61–70 of 143 articles
« Prev 1 5 6 7 8 9 15 Next »
Advertisements