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
Articles by Niharika Aitam
Page 5 of 14
Priority Queue using Queue and Heapdict module in Python
A priority queue is an abstract data type similar to a regular queue, but each element has an associated priority that determines the order of removal. Elements with higher priority are dequeued before those with lower priority. Priority queues are commonly implemented using heaps, arrays, or balanced trees. The most efficient implementation uses a heap, which is a binary tree where each node's value is greater than or equal to its children's values. Types of Priority Queues There are two main types of priority queues ? Min Priority Queue − Elements with lower priority values ...
Read MoreHow to check for a substring in a PySpark dataframe?
PySpark is a Python library that provides an interface to Apache Spark, a distributed computing system for processing large datasets. PySpark allows you to write Spark applications using Python, making it accessible for Python developers to work with big data. What is Substring Checking in PySpark? Substring checking in PySpark DataFrames involves searching for specific patterns or text within column values. This is commonly used for data filtering, pattern matching, and text analysis operations. PySpark provides several built-in functions to perform substring operations efficiently across distributed datasets. Setting Up PySpark First, let's create a sample DataFrame ...
Read MoreHow to check horoscope using Python?
Python can be used to create a horoscope checker by web scraping horoscope websites. This tutorial shows how to fetch daily horoscope predictions using BeautifulSoup and the requests library. Installing Required Packages First, install the required packages − pip install beautifulsoup4 requests The output shows successful installation − Collecting beautifulsoup4 Downloading beautifulsoup4-4.12.2.tar.gz (520 kB) Successfully installed beautifulsoup4-4.12.2 requests-2.31.0 Basic Horoscope Checker Here's a simple script to fetch horoscope predictions − import requests from bs4 import BeautifulSoup # Zodiac signs mapped to their numeric IDs ...
Read MoreHow to check if the PyMongo Cursor is Empty?
PyMongo is a Python library that provides a way to interact with MongoDB, the popular NoSQL document-oriented database. It allows developers to easily connect to MongoDB instances and perform operations like inserting, retrieving, and querying documents. Understanding PyMongo Cursors A cursor in MongoDB is an object that points to query results. When you execute the find() method, the results are returned as a cursor object. You can iterate through this cursor to access the documents in the result set. In PyMongo, the cursor is represented by the Cursor class. This object contains the results of your search ...
Read MoreHow to check whether user\'s internet is on or off using Python?
When building Python applications, you often need to verify whether the user's system has an active internet connection. This can be accomplished through several approaches: sending HTTP requests, establishing socket connections, or using system ping commands. Using requests.get() Method The requests module provides a simple way to send HTTP requests. By attempting to connect to a reliable website, we can determine internet connectivity ? Syntax requests.get(url, timeout=seconds) Where url is the website URL and timeout is the maximum waiting time for a response. Example import requests def check_internet_requests(): ...
Read MoreHow to click a href link from bootstrap tabs using Python?
Bootstrap is a popular HTML, CSS, and JavaScript framework for developing responsive web applications. When working with Bootstrap tabs, you may need to programmatically click href links within tab components. Python's Selenium library provides the perfect solution for automating such interactions. The Selenium Library Selenium is an open-source automation testing tool that allows you to control web browsers programmatically. It's primarily used for automated testing of web applications but is also valuable for web scraping and automating repetitive browser tasks. Selenium supports multiple programming languages including Python, Java, C#, and Ruby, and works with browsers like Chrome, Firefox, ...
Read MoreHow to clone webpage using pywebcopy in python?
Python provides the pywebcopy module that allows us to download and store entire websites including all images, HTML pages, and other files to our local machine. The save_webpage() function is the primary method for cloning webpages. Installing pywebcopy Module First, install the pywebcopy module using pip ? pip install pywebcopy On successful installation, you will get output similar to this ? Looking in indexes: https://pypi.org/simple Collecting pywebcopy Downloading pywebcopy-7.0.2-py2.py3-none-any.whl (46 kB) Installing collected packages: pywebcopy Successfully installed pywebcopy-7.0.2 Syntax The basic syntax for using the save_webpage() function ...
Read MoreHow to communicate JSON data between Python and Node.js?
JSON (JavaScript Object Notation) is a lightweight text-based format for transferring and storing data between different programming languages. Python provides built-in JSON support through the json module, while Node.js has native JSON parsing capabilities. To communicate JSON data between Python and Node.js, we typically use HTTP requests where one service acts as a server and the other as a client. This enables seamless data exchange between the two platforms. Installing Required Dependencies For Python, install Flask to create a web server: pip install flask requests For Node.js, install the request-promise module: ...
Read MoreHow to Color Scatterplot by a variable in Matplotlib?
Matplotlib allows you to color scatterplot points by a variable using several parameters in the scatter() function. The main parameters are c (for color mapping), cmap (colormap), and alpha (transparency). Matplotlib is a powerful plotting library that extends NumPy's capabilities for data visualization. The pyplot module provides an easy interface for creating customized scatter plots with variable-based coloring. Using a Colormap A colormap maps continuous numerical values to a range of colors. Use the cmap parameter to specify the colormap and c to provide the values that determine each point's color. Syntax plt.scatter(x, y, ...
Read MoreHow to choose elements from the list with different probability using NumPy?
NumPy provides several methods to randomly choose elements from a list with different probabilities. The probability values must sum to 1.0. Here are three main approaches using NumPy's random module. Using numpy.random.choice() The choice() function randomly samples elements from a 1-D array with specified probabilities ? Syntax numpy.random.choice(a, size=None, replace=True, p=None) Parameters: a − Input array or list of elements size − Output shape (optional) replace − Whether sampling is with replacement (default: True) p − Probabilities for each element (must sum to 1) Example 1: 1-D Array ...
Read More