Python Pandas – pandas.api.types.is_file_like() Function
In this article, we will be looking toward the functionality of pandas.api.types.is_file_like() from the pandas.api.types module with its various examples in the Python language.
An object must be an iterator AND have a read or write method as an attribute to be called file-like. It is important to note that file-like objects must be iterable, but iterable objects do not have to be file-like.
Pandas.api.types.is_file_like() method is used to check if the object is a file-like object.
Parameters: obj: the object we pass in to check.
Returns: boolean value. True if object has file like properties, false if it doesn’t.
Under this article, the pandas.api.types package and the NumPy package is imported and a NumPy array is checked if it’s a file-like object. As array object is not file like pandas.api.types.is_file_like() returns False .
In this example, the StringIO is used which is an in-memory file-like object that performs newline changes. Since it is a file type object pandas.api.types.is_file_like() method returns True when checked.
under this example, a text file named “file1.txt” is checked if it’s a file-like object through the pandas.api.types.is_file_like() method returns True when the file object is checked if its file object type.
Click here to view the used file-file1.txt.
Please Login to comment...