Pradeep Elance has Published 445 Articles

Add new column in Pandas Data Frame Using a Dictionary

Pradeep Elance

Pradeep Elance

Updated on 30-Jun-2020 08:46:10

877 Views

Pandas Data Frame is a two-dimensional data structure, i.e., data is aligned in a tabular fashion in rows and columns. It can be created using python dict, list, and series etc. In this article, we will see how to add a new column to an existing data frame.So first let's ... Read More

__name__ (A Special variable) in Python

Pradeep Elance

Pradeep Elance

Updated on 30-Jun-2020 08:36:00

2K+ Views

Unlike other programming languages, python is not designed to start execution of the code from a main function explicitly. A special variable called __name__ provides the functionality of the main function. As it is an in-built variable in python language, we can write a program just to see the value ... Read More

a.sort, sorted(a), np_argsort(a) and np.lexsort(b, a) in Python

Pradeep Elance

Pradeep Elance

Updated on 30-Jun-2020 08:34:19

513 Views

Ordering of data elements in a specific order is a frequently needed operation. To sort elements in an array, python uses the functions named sorted() and array.sort().sorted(array)This function returns a sorted array without modifying the original array.a = [9, 5, 3, 1, 12, 6] b = sorted([9, 5, 3, 1, ... Read More

Heap queue (or heapq) in Python

Pradeep Elance

Pradeep Elance

Updated on 09-Jun-2020 13:17:18

5K+ Views

Heap queue is a special tree structure in which each parent node is less than or equal to its child node. In python it is implemented using the heapq module. It is very useful is implementing priority queues where the queue item with higher weight is given more priority in ... Read More

Get match indices in Python

Pradeep Elance

Pradeep Elance

Updated on 04-Jun-2020 12:27:24

459 Views

Two lists are given. We need to find the index of the elements from the first list whose values match with the elements in the second list.With indexWe simply design follow to get the value of the element in the second list and extract the corresponding index from the first ... Read More

Get last N elements from given list in Python

Pradeep Elance

Pradeep Elance

Updated on 04-Jun-2020 12:25:14

962 Views

Given a Python list we want to find out only e e the last few elements.With slicingThe number of positions to be extracted is given. Based on that we design is slicing technique to slice elements from the end of the list by using a negative sign.Example Live DemolistA = ['Mon', ... Read More

Get key with maximum value in Dictionary in Python

Pradeep Elance

Pradeep Elance

Updated on 04-Jun-2020 12:22:34

637 Views

A Python dictionary contains key value pairs. In this article we will see how to get the key of the element whose value is maximum in the given Python dictionary.With max and getWe use the get function and the max function to get the key.Example Live DemodictA = {"Mon": 3, "Tue": ... Read More

Get key from value in Dictionary in Python

Pradeep Elance

Pradeep Elance

Updated on 04-Jun-2020 12:19:41

3K+ Views

Python dictionary contains key value pairs. In this article we aim to get the value of the key when we know the value of the element. Ideally the values extracted from the key but here we are doing the reverse.With index and valuesWe use the index and values functions of ... Read More

Get indices of True values in a binary list in Python

Pradeep Elance

Pradeep Elance

Updated on 04-Jun-2020 12:17:42

590 Views

When a Python list contains values like true or false and 0 or 1 it is called binary list. In this article we will take a binary list and find out the index of the positions where the list element is true.With enumerateThe enumerate function extracts all the elements form ... Read More

Get first index values in tuple of strings in Python

Pradeep Elance

Pradeep Elance

Updated on 04-Jun-2020 12:15:28

267 Views

We have a tuple of strings. We are required to create a list of elements which are the first character of these strings in the tuple.With indexWe design a for loop to take each element and extract the first character by applying the index condition as 0. Then the list ... Read More

Advertisements