by Suf | Jan 15, 2022 | Data Science, Programming, Python, Tips
NaN stands for Not a Number. You may encounter the error ValueError: cannot convert float NaN to integer when attempting to convert a column in a Pandas DataFrame from a float to an integer, and the column contains NaN values. You can solve this error by either...
by Suf | Jan 15, 2022 | Programming, Python, Tips
You can create a nested dictionary in Python by placing comma-separated dictionaries within curly braces {}. A Python nested dictionary allows you to store and access data using the key-value mapping structure within an existing dictionary. This tutorial will go...
by Suf | Jan 13, 2022 | Programming, Python, Tips
The easiest way to iterate over a dictionary is to use the in operator with a for loop. For example, for i in dict: print(i) iterate over the keys in the dictionary. We can use square brackets together with the keys to retrieve the values in the dictionary. For...
by Suf | Jan 12, 2022 | Programming, Python, Tips
The easiest way to check if a key exists in a Python dictionary is to use the in operator. This operator evaluates the membership of a value in a dictionary and will evaluate to True if the key exists, otherwise to False. This tutorial will go through the in operator...
by Suf | Jan 12, 2022 | Programming, Python, Tips
You can sort a dictionary by value in Python using the sorted() function. The sorted() function takes three parameters: object, key, and reverse. Note that in Python 3.7 and later versions, dictionaries are sorted by order of item insertion. For earlier versions,...
by Suf | Jan 10, 2022 | Programming, Python, Tips
The easiest way to add a new value to a dictionary is to use the subscript notation: dictionary_name[key] = value. This tutorial will go through the various ways to add key-value pairs to a Python dictionary with code examples. Table of contentsWhat is a Python...