Python pandas.api.types.is_dict_like() Function
In this article, we will be looking at the insight of the is_dict_like() function from the pandas.api.types package with various examples in a python programming language.
is_dict_like is a method that helps to specify whether the given object for the is_dict_like method is a dictionary or not.
Syntax: pandas.api.types.is_dict_like(dict_object)
Parameters:
- dict_object- It may be a dictionary or object that holds the dictionary.
Returns:
This function will return boolean values i.e., either true or false. If the parameter passed is a dictionary or object that holds a dictionary then it returns true. Else false.
Example 1:
In this example, a dictionary is passed to the is_dict_like method so it returned a boolean true value.
# import necessary packages
import pandas.api.types
pandas.api.types.is_dict_like({"Key": "Value"})
Output:
True
Example 2:
Under this example, an object which holds a dictionary is passed as a parameter to the is_dict_like method so it returned a boolean true value.
# import necessary packages
import pandas.api.types
# creating a dictionary
dictionary_obj = {"Geek": 4, "For": 3, "geeks": 5}
pandas.api.types.is_dict_like(dictionary_obj)
Output
True
Example 3:
In this example, a list of strings is passed as a parameter to the is_dict_like method which is not a dictionary. So it returns False.
# import necessary packages
import pandas.api.types
# passing a list to is_dict_like
pandas.api.types.is_dict_like(['Geeks', 'for', 'Geeks'])
Output
False