Tag: Check
Python : Check if a process is running by name and find it’s Process ID (PID)
In this article we will discuss a cross platform way to find a running process PIDs by name using psutil. To install python’s psutil library use, Advertisements pip install psutil Check if a process is running To check if process is running or not, let’s iterate over all the running process using psutil.process_iter() and match …
Python : Check if a process is running by name and find it’s Process ID (PID)Read More
Check if a Pandas DataFrame is empty or not
In this article, we will discuss four different ways to check if a given DataFrame is empty or not. Check whether DataFrame is empty using Dataframe.empty In Python’s pandas, the Dataframe class provides an attribute empty i.e. Dataframe.empty It return True if DatafFrame contains no data. Advertisements Let’s see an example, Create an empty DatafFrame …
Python : Check if a String contains a sub string & find it’s index | case insensitive
In this article we will discuss different ways to check if a sub-string exists in another string and if yes then find it’s index. Will also explore ways to check the existence of sub-string in case in-sensitive manner by ignoring case. Check if a String contains another string or character using “in” and “not in” …
Python : Check if a String contains a sub string & find it’s index | case insensitiveRead More
Pandas : Check if a value exists in a DataFrame using in & not in operator | isin()
In this article we will dicuss different ways to check if a given value exists in the dataframe or not. First of all, we need to import the pandas module i.e. Advertisements import pandas as pd Let’s create a dataframe, # List of Tuples empoyees = [(‘jack’, 34, ‘Sydney’, 155) , (‘Riti’, 31, ‘Delhi’ , …
Pandas : Check if a value exists in a DataFrame using in & not in operator | isin()Read More
Check for Duplicates in a List in Python
In this article, we will discuss different ways to check if a Python List contains any duplicate element or not. Suppose we have a list of elements i.e. listOfElems = [‘Hello’, ‘Ok’, ‘is’, ‘Ok’, ‘test’, ‘this’, ‘is’, ‘a’, ‘test’] Now we want to check if this list contains any duplicate element or not. There are …
How to get & check data types of Dataframe columns in Python Pandas
In this article we will discuss different ways to fetch the data type of single or multiple columns. Also see how to compare data types of columns and fetch column names based on data types. Use Dataframe.dtypes to get Data types of columns in Dataframe In Python’s pandas module Dataframe class provides an attribute to …
How to get & check data types of Dataframe columns in Python PandasRead More
Check the first or last character of a string in python
In this article, we will discuss different ways to check the content of the first or last character of a string in python. Indexing in String Every character in a string has an index number associated with it. This index can be a positive or negative number. For example, we have a string, Advertisements sample_str …
Check the first or last character of a string in pythonRead More
Python: Three ways to check if a file is empty
In this article, we will discuss different ways to check if a file is empty i.e. its size is 0 using os.stat() or os.path.getsize() or by reading its first character. Check if a file is empty using os.stat() in Python Python provides a function to get the statistics about the file, Advertisements os.stat(path, *, dir_fd=None, …
Python: Check if a List is empty
In this article, we will discuss different ways to check if a list is empty or not. We will also see how to check if a list of lists is empty or not using for loop, List comprehension, and all() function.Table of Contents Check if a list is empty using ‘not’ operator in python Check …
Check if all elements in a list are None in Python
In this article we will discuss different ways to check if a list contains only None or not. Suppose we have a list, Advertisements sample_list = [None, None, None, None] Now we want to confirm that all items in this list are None. There are different ways to do that. Let’s discuss them one by …