Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Python Articles
Page 148 of 855
What are the Resources for Learning Advanced Python Programming?
Python's demand as a programming language has driven it to a wealth of resources for learning its different aspects. While beginners have various tutorials and guides to help them get started, advanced learners often struggle to find resources that cater to their specific needs. In this article, we'll explore the range of resources aimed at taking your Python skills to the next level, covering topics such as advanced language features, design patterns, performance optimization, and more. Advanced Python Language Features To get the most out of Python, it's important to master its advanced language features. These features enable ...
Read MoreWhat are Some Interesting Python Programs?
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
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
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
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 MorePython program to find common array elements
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 MorePython Program to Check if two arrays are equal
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 MoreDrop rows from the dataframe based on certain condition applied on a column
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 MoreDrop rows containing specific value in pyspark dataframe
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 MoreDrop One or Multiple Columns From PySpark DataFrame
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