Tumgik
sparkbyexamples · 1 year
Text
Python Active Virtual Environment (venv)
How to active venv virtual environment in Python 3? The venv module is used to create a lightweight virtual environment, this environment created on top of existing python installation In Linux, Unix, or Mac you can activate the Python virtual environment by using the below command 1. Create a Virtual Environment First, let’s create a virtual environment. The below example creates a virtual…
View On WordPress
0 notes
sparkbyexamples · 1 year
Text
Transform List using Python map()
Transform List using Python map()
How to transform a list using the python map() function? We often required to transform every element of the list and return a new list. Python provides several ways to transform a list, using map() is one of the most used to transform iterable objects including list. In this article, first, will see how to apply the transformation in tradition way using for loop and then use the map() finally…
Tumblr media
View On WordPress
0 notes
sparkbyexamples · 1 year
Text
Sort using Lambda in Python
Sort using Lambda in Python
How to perform a sort with lambda in python? A lambda function is a small anonymous function, it can be created or defined using the lambda keyword. You can use the lambda as the key function when sorting a list. for example, use key=lambda to the sort() function to order list. Syntax Following is the syntax of the python sort() and sorted() functions using lambda as key. # syntax of…
View On WordPress
0 notes
sparkbyexamples · 1 year
Text
Python Lambda using if else
Python Lambda using if else
How to use an if else in Python lambda? You can use the if-else statement in a lambda as part of an expression. The lambda should have only one expression so here, it should be if-else. The if returns the body when the condition is satisfied, and the else body is returned when the condition is not satisfied. A Python lambda function is used to execute an anonymous function. This function can take…
View On WordPress
0 notes
sparkbyexamples · 1 year
Text
Python map() with Multiple Arguments
Python map() with Multiple Arguments
How to pass multiple iterable as arguments to a python map? You can use python map() with multiple iterable arguments by creating a function with multiple arguments and using it on map() with multiple iterables. The map() function in Python is used to apply the transformation to an iterable object like a list, tuple, or set, etc. whereas A Python lambda function is a small anonymous function that…
View On WordPress
0 notes
sparkbyexamples · 1 year
Text
Python Lambda with Multiple Arguments
Python Lambda with Multiple Arguments
Python lambda can be used with multiple arguments and these arguments are used in evaluating an expression to return a single value. A Python lambda function is used to execute an anonymous function, an anonymous meaning function without a name. This function can take any number of arguments, but can only have one expression and they can be used wherever function objects are required. Here is the…
View On WordPress
0 notes
sparkbyexamples · 1 year
Text
Python map() with Lambda Function
Python map() with Lambda Function
Using lambda with map() function is the most common way of usage in Python to perform transformations on iterable objects (e.g., list, tuple, set). What is map() Function? The map() function in Python is used to apply the transformation to an iterable object like a list, tuple, or set e.t.c, this applies the given transformation function to each item of an iterable (e.g., list, tuple, set). You…
View On WordPress
0 notes
sparkbyexamples · 1 year
Text
Python Lambda Function
A Python lambda operator or lambda function is a small anonymous function, an anonymous meaning function without a name. The Lambda functions are mainly used in combination with the functions filter(), map() and reduce(). This function can take any number of arguments, but can only have one expression and they can be used wherever function objects are required. Key Points of Python Lambda…
View On WordPress
0 notes
sparkbyexamples · 1 year
Text
Pad String with Spaces in Python
Pad String with Spaces in Python
How to pad the string with spaces in Python? Adding some characters to the string is known as Padding or filling and is useful when you wanted to make a string with a specific length. In Python, rjust() method can be used to pad spaces at the beginning of the string and ljust() can be used to pad spaces at the end of the string. With the ljust() and rjust() you can fill in any characters but in…
View On WordPress
0 notes
sparkbyexamples · 1 year
Text
Python sorted() Function
The sorted() function in python is used to get the sorted list of the specified iterable object. The iterable can be a list, tuple, string, dictionary, set, and frozenset. This function takes three parameters iterable, key, and reverse. The key is used to call a function and the reverse is used to change the sorting order. Related: list.sort() Function 1 Sorted Function Syntax Following is the…
View On WordPress
0 notes
sparkbyexamples · 1 year
Text
Python Sort Array Values
Python Sort Array Values
Use np.sort() to sort array values in an ordered sequence in Python. By using this you can sort an N-dimensional array of any data type. This function gives a sorted copy of the source array or input array without modifying the input array. Note that Python language doesn’t have an array type but you can use the NumPy library to use arrays in Python. This article explains how to create and sort…
Tumblr media
View On WordPress
0 notes
sparkbyexamples · 1 year
Text
Python String join() Method
Python String join() Method
The Python str.join() method is used to join elements or values from a sequence object (list, set, tuple e.t.c) into a string by comma, space, or any custom separator. This method is called on the separator string and passed the sequence of strings as an argument and returns a string after joining. 1. Syntax of join() Following is the syntax of the string join() method. # Syntax of…
View On WordPress
0 notes
sparkbyexamples · 1 year
Text
Python Sort List in Reverse Order
Python Sort List in Reverse Order
How to sort a list in reverse order in Python? You can use the reverse=True on built-in sorted() function in Python to sort a list in reverse order (descending). This method will return a new list after sorting a list. Alternatively, you can also use the sort() function with reverse=True to sort the list in reverse order, this updates the sort in place, meaning that it will modify the original…
View On WordPress
0 notes
sparkbyexamples · 1 year
Text
Python Sort List of Numbers or Integers
Python Sort List of Numbers or Integers
You can use the built-in sorted() function in Python to sort a list of numbers or integer values. This method will return a new list after sorting list. Alternatively, you can also use the sort() function to sort numbers, this updates the sort in place, meaning that it will modify the original list and you won’t need to create a new list. 1. Quick Examples of Sorting List of Numbers If you are…
View On WordPress
0 notes
sparkbyexamples · 1 year
Text
Python Sort List Alphabetically
Python Sort List Alphabetically
To sort a list in alphabetical order in Python, you can use the sort method on the list. This method will sort the list in place, meaning that it will modify the original list and you won’t need to create a new list. You can also use the sorted function to sort a list. This function returns a new sorted list, without modifying the original list. 1. Quick Examples of Sorting List…
View On WordPress
0 notes
sparkbyexamples · 1 year
Text
Pandas Series.isin() Function
Pandas Series.isin() function is used to check whether values are contained in the given Series object or not. it returns a Series of booleans indicating if each element is in values, True when present, and False when not. In this article, I will explain the syntax of Series.isin() function, its parameters, and how to check whether values are contained in given Series object with examples. 1.…
View On WordPress
0 notes
sparkbyexamples · 1 year
Text
PySpark SQL Read Hive Table
PySpark SQL Read Hive Table
How to read a Hive table into PySpark DataFrame? PySpark SQL supports reading a Hive table to DataFrame in two ways: the SparkSession.read.table() method and the SparkSession.sql() statement. In order to read a Hive table in PySpark, you need to create a SparkSession with enableHiveSupport(). This method is available pyspark.sql.SparkSession.builder.enableHiveSupport() which enables Hive…
Tumblr media
View On WordPress
0 notes