Articles on Trending Technologies

Technical articles with clear explanations and examples

How do you plot a vertical line on a time series plot in Pandas?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 4K+ Views

When working with time series data in Pandas, you often need to highlight specific dates or events by adding vertical lines to your plots. This can be achieved using matplotlib's axvline() method on the plot axes. Creating a Time Series DataFrame First, let's create a sample time series dataset with dates as the index ? import pandas as pd import matplotlib.pyplot as plt # Create a DataFrame with date range df = pd.DataFrame(index=pd.date_range("2019-07-01", "2019-07-31")) df["value"] = range(1, 32) # Sample values for each day print(df.head()) ...

Read More

How to create a simple screen using Tkinter?

Prasad Naik
Prasad Naik
Updated on 25-Mar-2026 627 Views

Tkinter is Python's standard GUI library for creating desktop applications. We will create a simple screen using the Tkinter library to demonstrate the basic setup. Algorithm Step 1: Import tkinter. Step 2: Create an object of the tkinter class. Step 3: Display the screen using mainloop(). Example Code Here's how to create a basic Tkinter window ? import tkinter as tk # Create the main window window = tk.Tk() # Set window title window.title("Simple Tkinter Screen") # Set window size window.geometry("400x300") # Start the event loop window.mainloop() ...

Read More

Python program to display various datetime formats

Prasad Naik
Prasad Naik
Updated on 25-Mar-2026 365 Views

The datetime module in Python provides powerful classes for manipulating dates and times. The strftime() method allows you to format dates and times in various ways using format codes. Basic Date Formatting Let's start with common date formats using format codes ? import datetime today = datetime.date.today() print("Day of the week:", today.strftime("%A")) print("Week number:", today.strftime("%W")) print("Day of the year:", today.strftime("%j")) Day of the week: Monday Week number: 47 Day of the year: 332 Various Date and Time Formats Here are more formatting options with complete date and time ...

Read More

How to have logarithmic bins in a Python histogram?

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 25-Mar-2026 5K+ Views

In Python, creating a logarithmic histogram involves using logarithmically spaced bins instead of linear ones. This is particularly useful when your data spans several orders of magnitude. We can achieve this using NumPy for generating logarithmic bins and matplotlib for plotting. Logarithmic bins are spaced exponentially rather than linearly, making them ideal for data that follows power-law distributions or spans wide ranges. Basic Example with Logarithmic Bins Let's create a simple histogram with logarithmic bins ? import matplotlib.pyplot as plt import numpy as np # Create sample data data = np.random.exponential(scale=2, size=1000) # ...

Read More

How to use regular expressions (Regex) to filter valid emails in a Pandas series?

Prasad Naik
Prasad Naik
Updated on 25-Mar-2026 865 Views

A regular expression is a sequence of characters that define a search pattern. In this program, we will use these regular expressions to filter valid and invalid emails in a Pandas series. We will define a Pandas series with different emails and check which email is valid using Python's re library for regex operations. Email Validation Regex Pattern The regex pattern for email validation contains several components ? ^: Anchor for the start of the string [a-z0-9]: Character class to match lowercase letters and digits [\._]?: Optional dot or underscore character @: Required @ symbol ...

Read More

Pandas program to convert a string of date into time

Prasad Naik
Prasad Naik
Updated on 25-Mar-2026 262 Views

In this program, we will convert date strings like "24 August 2020" into datetime format using Pandas. The to_datetime() function automatically parses various date string formats and converts them to standardized datetime objects. Algorithm Step 1: Define a Pandas series containing date strings. Step 2: Convert these date strings into datetime format using to_datetime(). Step 3: Print the results. Example Let's convert different date string formats to datetime ? import pandas as pd series = pd.Series(["24 August 2020", "25 December 2020 20:05"]) print("Original Series:") print(series) datetime_series = pd.to_datetime(series) print("DateTime Format:") ...

Read More

Finding the multiples of a number in a given list using NumPy

Prasad Naik
Prasad Naik
Updated on 25-Mar-2026 2K+ Views

Finding multiples of a number in a list is a common task in data analysis. NumPy provides efficient methods to identify multiples using vectorized operations and built-in functions like argwhere() and modulo operations. Using Basic Loop Method The traditional approach uses a loop to check each element ? import numpy as np listnum = np.arange(1, 20) multiples = [] n = 5 print("NumList:", listnum) for num in listnum: if num % n == 0: multiples.append(num) ...

Read More

How to calculate the frequency of each item in a Pandas series?

Prasad Naik
Prasad Naik
Updated on 25-Mar-2026 562 Views

In this program, we will calculate the frequency of each element in a Pandas series. The function value_counts() in the pandas library helps us to find the frequency of elements. Algorithm Step 1: Define a Pandas series. Step 2: Print the frequency of each item using the value_counts() function. Example Code import pandas as pd series = pd.Series([10, 10, 20, 30, 40, 30, 50, 10, 60, 50, 50]) print("Series:", series) frequency = series.value_counts() print("Frequency of elements:", frequency) Output Series: 0 10 1 ...

Read More

How to get the nth percentile of a Pandas series?

Prasad Naik
Prasad Naik
Updated on 25-Mar-2026 1K+ Views

A percentile is a statistical measure that indicates the value below which a certain percentage of observations fall. In Pandas, you can calculate the nth percentile of a series using the quantile() method. Syntax series.quantile(q) Parameters: q − The quantile value between 0 and 1 (percentile/100) Example Here's how to calculate the 50th percentile (median) of a Pandas series ? import pandas as pd # Create a Pandas series series = pd.Series([10, 20, 30, 40, 50]) print("Series:") print(series) # Calculate 50th percentile percentile_50 = series.quantile(0.5) print(f"The 50th ...

Read More

Python xticks in subplots

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 5K+ Views

Subplots allow you to display multiple plots in a single figure by dividing it into a grid. When working with subplots, you can customize the x-axis ticks for each subplot independently using plt.xticks(). Understanding Subplot Layout The plt.subplot() function creates subplots using three parameters: nrows, ncols, and index. For example, plt.subplot(121) creates a 1×2 grid and selects the first subplot. Basic Subplot with Different X-ticks Here's how to create two subplots with custom x-tick positions − import matplotlib.pyplot as plt line1 = [21, 14, 81] line2 = [31, 6, 12] # First ...

Read More
Showing 1–10 of 61,303 articles
« Prev 1 2 3 4 5 6131 Next »
Advertisements