Pandas – How to Find DataFrame Row Indices with NaN or Null Values

Problem Formulation and Solution Overview This article will show you how to find DataFrame row indices in Python with NaN or Null (empty) values. To make it more interesting, we have the following scenario: Rivers Clothing has given you a CSV file that requires a clean-up to make it usable for Payroll and Data Analysis. … Read more

Print a List Without Quotes in Python – 5 Best Ways

Problem Formulation 💬 How to print a list without quotes in Python? Given a Python list of strings such as [‘1’, ‘2’, ‘3’]. If you print the list to the shell using print([‘1’, ‘2’, ‘3’]), the output is enclosed in square brackets and the strings have quotes like so: “[‘1’, ‘2’, ‘3’]”. This article will … Read more

How to Print a String and an Integer

Problem Formulation and Solution Overview In this article, you’ll learn how to print a string and an integer together in Python. To make it more fun, we have the following running scenario: The Finxter Academy has decided to send its users an encouraging message using their First Name (a String) and Problems Solved (an Integer). … Read more

How to Find the Shortest String in a Python List?

Use Python’s built-in min() function with a key argument to find the shortest string in a list. Call min(lst, key=len) to return the shortest string in lst using the built-in len() function to associate the weight of each string—the shortest string will be the minimum. Problem Formulation Given a Python list of strings. Find the … Read more

How to Find the Longest String in a Python List?

Use Python’s built-in max() function with a key argument to find the longest string in a list. Call max(lst, key=len) to return the longest string in lst using the built-in len() function to associate the weight of each string—the longest string will be the maximum. Problem Formulation Given a Python list of strings. Find the … Read more

How to Apply a Function to Each Cell in a Pandas DataFrame?

Problem Formulation Given the following DataFrame df: 💬 Challenge: How to apply a function f to each cell in the DataFrame? For example, you may want to apply a function that replaces all odd values with the value ‘odd’. Solution: DataFrame applymap() The Pandas DataFrame df.applymap() method returns a new DataFrame where the function f … Read more

How to Ignore Case in Python Strings

Problem Formulation and Solution Overview In this article, you’ll learn how to ignore (upper/lower/title) case characters when dealing with Strings in Python. The main reason for ignoring the case of a String is to perform accurate String comparisons or to return accurate search results. For example, the following three (3) Strings are not identical. If … Read more