Tag: Empty
Python : How to check if a directory is empty ?
In this article we will discuss different ways to check if a directory is empty or not. Python’s os module provides a function to get the list of files or folder in a directory i.e. Advertisements os.listdir(path=’.’) It returns a list of all the files and sub directories in the given path. Now if the …
Python : How to Get List of all empty Directories ?
In this article we will discuss how to get list of all empty directories. Python’s os module provides a function to iterate over a directory tree i.e. Advertisements os.walk(path) It iterates of the directory tree at give path and for each directory or sub directory it returns a tuple containing, (<Dir Name> , <List of …
Python : How to Get List of all empty Directories ?Read More
Pandas : How to create an empty DataFrame and append rows & columns to it in python
In this article we will discuss different ways to create an empty DataFrame and then fill data in it later by either adding rows or columns. Suppose we want to create an empty DataFrame first and then append data into it at later stages. Let’s see how to do that, Advertisements Import python’s pandas module like …
Pandas : How to create an empty DataFrame and append rows & columns to it in pythonRead 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: 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: How to create an empty list and append items to it?
In this article, first we will discuss different ways to create an empty list and then we will see how to append elements to it using for loop or one liner list comprehension. There are two ways to create an empty list in python i.e. using [] or list(). Let’s check out both of them …
Python: How to create an empty list and append items to it?Read More
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 …
Create an empty Numpy Array of given length or shape & data type in Python
In this article we will discuss different ways to create an empty 1D,2D or 3D Numpy array and of different data types like int or string etc. Python’s numpy module provides a function empty() to create new arrays, Advertisements numpy.empty(shape, dtype=float, order=’C’) It accepts shape and data type as arguments. Returns a new array of …
Create an empty Numpy Array of given length or shape & data type in PythonRead More
Create an empty 2D Numpy Array / matrix and append rows or columns in python
In this article we will discuss how to create an empty matrix or 2D numpy array first using numpy.empty() and then append individual rows or columns to this matrix using numpy.append(). Before moving forward, let’s have a quick look at the two functions which we are going to use in this article, Advertisements numpy.empty() numpy.empty(shape, …
Create an empty 2D Numpy Array / matrix and append rows or columns in pythonRead More
Python: How to create an empty set and append items to it?
In this article, first we will discuss different ways to create an empty set and then we will see how to add or append items to the empty set. In python there are two ways to create an empty set, Advertisements Using set() Using empty set literal Let’s discuss both of them one by one, …
Python: How to create an empty set and append items to it?Read More