Python Articles

Page 144 of 855

What are Some Interesting Python Programs?

Tushar Sharma
Tushar Sharma
Updated on 27-Mar-2026 343 Views

Python is a versatile programming language known for its simplicity and readability, making it a popular choice for a wide range of applications. In this article, we'll explore seven interesting Python programs that showcase the language's power and can inspire you to create your own unique projects. These programs cover various domains including machine learning, web development, data visualization, and more. DeepArt: Neural Style Transfer with Python DeepArt is a fascinating application that combines art and technology using neural style transfer. This technique allows you to apply the style of one image (such as a painting) to the ...

Read More

__file__ (A Special Variable) in Python

Sarika Singh
Sarika Singh
Updated on 27-Mar-2026 4K+ Views

The __file__ variable in Python is a special attribute that stores the path to the current script or module from which it is accessed. It is automatically set by the Python interpreter when a script is executed or a module is imported. This variable allows you to determine the exact location of the current file, irrespective of where the Python interpreter is run. Understanding __file__ Behavior The value of __file__ can be either a relative path or an absolute path, depending on how the script is executed ? For scripts that ...

Read More

__exit__ in Python

Sarika Singh
Sarika Singh
Updated on 27-Mar-2026 4K+ Views

In Python, some special methods have names that start and end with double underscores. These are called dunder methods. One such method is __exit__, which is used in context managers for cleanup tasks. Context Manager in Python Context Managers help to manage resources such as files, database connections, or network links. It sets up a temporary environment to run a block of code. When the block ends, Python closes the file or disconnects the connection automatically. This prevents unnecessary resource consumption when we leave a file open or keep a connection (such as network, database) active. ...

Read More

__call__ in Python

Sarika Singh
Sarika Singh
Updated on 27-Mar-2026 818 Views

In Python, everything is treated as an object, including integers, strings, classes, and even functions. It provides a special method named __call__ that allows an instance of a class (i.e. object) to behave like a function (i.e. we can call/invoke it). When we define the __call__ method inside a class, we can call its instance (object) using parentheses, just like a regular function. Syntax Following is the syntax to use the __call__ method inside a class − class MyClass: def __call__(self, *args, **kwargs): ...

Read More

Python program to find common array elements

Nikhitha Chowdary Manne
Nikhitha Chowdary Manne
Updated on 27-Mar-2026 338 Views

Finding common elements in arrays is a frequent task in data processing. Python provides several approaches depending on whether you're working with multi-dimensional arrays or comparing separate arrays. Finding Common Elements in Multi-Dimensional Arrays For multi-dimensional arrays, we can use the intersection_update() method with sets to find elements that appear in all sub-arrays ? Input Output Scenario Consider a 2D array with multiple sub-arrays ? arr = [[1, 2, 3, 4], [3, 4, 5, 6], [7, 8, 3, 4], [4, 9, 8, 3], [4, 3, 10, 12]] # Elements 3 and 4 appear ...

Read More

Python Program to Check if two arrays are equal

Nikhitha Chowdary Manne
Nikhitha Chowdary Manne
Updated on 27-Mar-2026 23K+ Views

Arrays are fundamental data structures in Python, and checking if two arrays are equal is a common operation. Python provides several techniques to compare arrays based on whether they contain the same elements, regardless of order. Understanding Array Equality Array equality can be checked in two ways: Element-wise comparison − Same elements at same positions Set-based comparison − Same elements regardless of order Let's explore different methods to check array equality ? Method 1: Using NumPy for Element-wise Comparison NumPy's array_equal() function compares arrays element by element ? import numpy ...

Read More

Drop rows from the dataframe based on certain condition applied on a column

Devesh Chauhan
Devesh Chauhan
Updated on 27-Mar-2026 1K+ Views

In this article, we will discuss different methods to drop rows from a DataFrame based on conditions applied to columns. We will use pandas to create and manipulate DataFrames, demonstrating various filtering techniques. Pandas is a powerful library that supports multiple file types including CSV, JSON, HTML, SQL, and Excel, making it an essential tool for data manipulation. Creating a Pandas DataFrame We will create a DataFrame consisting of player profiles with their ratings and salaries arranged in rows and columns ? import pandas as pd dataset = { "Player ...

Read More

Drop rows containing specific value in pyspark dataframe

Devesh Chauhan
Devesh Chauhan
Updated on 27-Mar-2026 1K+ Views

When dealing with large datasets, PySpark provides powerful tools for data processing and manipulation. PySpark is Apache Spark's Python API that allows you to work with distributed data processing in your local Python environment. In this tutorial, we'll learn how to drop rows containing specific values from a PySpark DataFrame using different methods. This selective data elimination is essential for data cleaning and maintaining data relevance. Creating a Sample PySpark DataFrame First, let's create a sample DataFrame to demonstrate the row dropping techniques ? from pyspark.sql import SparkSession # Create SparkSession spark = SparkSession.builder.appName("DropRowsDemo").getOrCreate() ...

Read More

Drop One or Multiple Columns From PySpark DataFrame

Devesh Chauhan
Devesh Chauhan
Updated on 27-Mar-2026 1K+ Views

A PySpark DataFrame is a distributed data structure built on Apache Spark that provides powerful data processing capabilities. Sometimes you need to remove unnecessary columns to optimize performance or focus on specific data. PySpark offers several methods to drop one or multiple columns from a DataFrame. Creating a PySpark DataFrame First, let's create a sample DataFrame to demonstrate column dropping operations ? from pyspark.sql import SparkSession import pandas as pd # Create SparkSession spark = SparkSession.builder.appName("DropColumns").getOrCreate() # Sample dataset dataset = { "Device name": ["Laptop", "Mobile phone", "TV", "Radio"], ...

Read More

Drop Empty Columns in Pandas

Devesh Chauhan
Devesh Chauhan
Updated on 27-Mar-2026 11K+ Views

Pandas DataFrames often contain empty columns filled with NaN values that can clutter your data analysis. Python provides several efficient methods to identify and remove these empty columns to create cleaner, more relevant datasets. What Are Empty Columns? In pandas, a column is considered empty when it contains only NaN (Not a Number) values. Note that columns with empty strings, zeros, or spaces are not considered empty since these values may carry meaningful information about your dataset. Creating a DataFrame with Empty Columns Let's start by creating a sample DataFrame that includes an empty column filled ...

Read More
Showing 1431–1440 of 8,549 articles
« Prev 1 142 143 144 145 146 855 Next »
Advertisements