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
Programming Articles
Page 34 of 2547
colorsys module in Python
The colorsys module in Python allows bidirectional conversions of color values between RGB (Red Green Blue) and other color spaces. The three other color spaces it supports are YIQ (Luminance In-phase Quadrature), HLS (Hue Lightness Saturation), and HSV (Hue Saturation Value). All coordinates range between 0 and 1, except I and Q values in YIQ color space which can range from -1 to 1. Available Functions The colorsys module provides six conversion functions ? Function Purpose Permitted Values rgb_to_yiq Convert RGB coordinates to YIQ coordinates 0 to 1 (RGB), -1 ...
Read MoreFilter in Python
The filter() function in Python creates a new iterator from elements of an iterable for which a function returns True. It's useful for extracting elements that meet specific criteria from lists, tuples, or other sequences. Syntax filter(function, iterable) Parameters: function − A function that returns True or False for each element iterable − Any sequence like list, tuple, set, or string to be filtered Basic Example Let's filter months that have 30 days from a list of months ? # List of months months = ['Jan', 'Feb', 'Mar', 'Apr', ...
Read MoreChange Data Type for one or more columns in Pandas Dataframe
Converting data types of columns in a Pandas DataFrame is essential for data analysis and calculations. Pandas provides several methods to change column data types efficiently. Using astype() The astype() method converts existing columns to specified data types. You can convert all columns or target specific ones ? Converting All Columns to String import pandas as pd # Sample dataframe df = pd.DataFrame({ 'DayNo': [1, 2, 3, 4, 5, 6, 7], 'Name': ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], 'Qty': [2.6, 5, ...
Read MoreCalculate n + nn + nnn + ? + n(m times) in Python
There are a variety of mathematical series which Python can handle gracefully. One such series involves repeated digits where we take a digit n and create a sequence: n + nn + nnn + ... up to m terms. For example, with n=2 and m=4, we get: 2 + 22 + 222 + 2222 = 2468. Approach We convert the digit to a string and concatenate it repeatedly to form numbers with multiple occurrences of the same digit. Then we sum all these generated numbers ? Example def sum_of_series(n, m): # ...
Read Morehowdoi in Python
The howdoi Python package is a command-line tool that provides instant answers to programming questions directly from Stack Overflow. It saves time by fetching code snippets and solutions without opening a web browser. Installation First, install the howdoi package using pip ? pip install howdoi Basic Usage Use howdoi followed by your programming question to get instant answers ? howdoi create a python list >>> l = [None] * 10 >>> l [None, None, None, None, None, None, None, None, None, None] Common Programming Queries ...
Read MoreHow to print without newline in Python?
In Python, the print() function adds a newline character by default at the end of each output. When you have multiple print statements, each output appears on a separate line. However, you can modify this behavior using the end parameter to print everything on a single line. Normal Print() Behavior By default, each print() statement ends with a newline character (), causing output to appear on separate lines ? Example print("Apple") print("Mango") print("Banana") Output Apple Mango Banana Using the end Parameter The end parameter controls what character(s) ...
Read MoreHow to download Google Images using Python
Google Images can be downloaded programmatically using Python packages that search and fetch images based on keywords. The google_images_download package provides a simple interface to download images by specifying search terms and parameters. Installation First, install the required package using pip ? pip install google_images_download Basic Image Download Here's how to download a limited number of images with URL printing enabled ? from google_images_download import google_images_download # Instantiate the class response = google_images_download.googleimagesdownload() # Set download parameters arguments = { "keywords": "lilly, hills", ...
Read MoreHow to clear screen in python?
When working with Python programs, you may need to clear the terminal screen programmatically to improve output readability. While you can manually clear the screen with Ctrl + L, Python provides ways to clear the screen automatically within your script. Python uses the os.system() function to execute system commands for clearing the screen. The command differs between operating systems: 'clear' for Unix/Linux/macOS and 'cls' for Windows. Basic Screen Clearing Function Here's how to create a cross-platform screen clearing function ? import os def clear_screen(): # For Unix/Linux/macOS (os.name is 'posix') ...
Read MoreFinding Mean, Median, Mode in Python without Libraries
Mean, Median and Mode are very frequently used statistical functions in data analysis. Python provides built-in functions and simple algorithms to calculate these measures without external libraries. Finding Mean Mean of a list of numbers is also called average of the numbers. It is found by taking the sum of all the numbers and dividing it by the count of numbers. In the below example we apply the sum() function to get the sum of the numbers and the len() function to get the count of numbers ? Example numbers = [21, 11, 19, 3, ...
Read MoreFind the k most frequent words from data set in Python
If there is a need to find the k most frequent words in a data set, Python can help us achieve this using the collections module. The collections module has a Counter class which counts the frequency of words after we supply a list of words to it. We also use the most_common() method to find the specified number of most frequent words. Basic Approach Using Counter In the below example we take a paragraph, create a list of words using split(), then apply Counter() to count word frequencies. Finally, most_common() returns the top k most frequent words ...
Read More