Find all Columns with NaN Values in Pandas DataFrame

Here are 4 ways to find all columns that contain NaN values in Pandas DataFrame: (1) Use isna() to find all columns with NaN values: Copy df.isna().any() (2) Use isnull() to find all columns with NaN values: Copy df.isnull().any() (3) Use isna() to select all columns with NaN values: Copy df[df.columns[df.isna().any()]] (4) Use isnull() to … Read more

How to Check the Version of the Python Interpreter

You can use the sys library in order to check the version of your Python Interpreter: Copy import sys print (sys.version) Here is an example of a version of the Python Interpreter: 3.8.2 Get the components of your version If you want to get the components of your version, you may use: Copy import sys … Read more

Join Tables from Different Databases in SQL Server

Here is the general syntax that you may use to join tables from two different databases in SQL Server: Copy SELECT tb_1.*, tb_2.* FROM [database_1].[table_schema].[table_name_1] tb_1 JOIN [database_2].[table_schema].[table_name_2] tb_2 ON tb_1.id = tb_2.id In the next section, you’ll see how to join two tables from two different databases in SQL Server. The tables and databases … Read more

How to Create a Temporary Table in SQL Server

Here are two approaches to create a temporary table in SQL Server: (1) The SELECT INTO approach: Copy SELECT column_1, column_2, column_3,… INTO #name_of_temp_table FROM table_name WHERE condition (2) The CREATE TABLE approach: Copy CREATE TABLE #name_of_temp_table ( column_1 datatype, column_2 datatype, column_3 datatype, . . column_n datatype ) Note that once you created the … Read more

How to Control a Keyboard using Python

You can use the PyAutoGUI library to control a keyboard using Python. To start, here is the command to install the PyAutoGUI library: Copy pip install pyautogui In this tutorial, you’ll see 4 scenarios that describe how to: 4 Scenarios to Control a Keyboard using Python Scenario 1: Type characters using the typewrite() function You can … Read more

Transpose Pandas DataFrame

To transpose Pandas DataFrame: Copy df = df.transpose() Let’s see how to apply the above syntax by reviewing 3 cases of: Case 1: Transpose Pandas DataFrame with a Default Index To start with a simple example, let’s create a DataFrame with 3 columns: Copy import pandas as pd data = {‘A’: [11, 22, 33], ‘B’: … Read more

How to Replace Items in a Python List

You can use a list comprehension to replace items in a Python list: Copy my_list = [‘item 1’, ‘item 2’, ‘item 3’,…] my_list = [‘new item’ if i==’old item’ else i for i in my_list] To better understand how to replace items in a Python list, you’ll see the following 3 scenarios about: Replacing an … Read more

Replace Characters in Strings in Pandas DataFrame

Here are two ways to replace characters in strings in Pandas DataFrame: (1) Replace character/s under a single DataFrame column: Copy df[‘column name’] = df[‘column name’].str.replace(‘old character’,’new character’) (2) Replace character/s under the entire DataFrame: Copy df = df.replace(‘old character’,’new character’, regex=True) In this short guide, you’ll see how to replace: Specific character under a … Read more

How to Control a Mouse using Python

In order to control a mouse using Python, you may use the PyAutoGUI library. You may then install the PyAutoGUI library using the following command (under Windows): Copy pip install pyautogui Next, you’ll see the following 4 scenarios which demonstrate how to control a mouse using Python by: Moving a mouse cursor to a specific … Read more

How to Convert NumPy Array to Pandas DataFrame

In this short guide, you’ll see how to convert a NumPy array to Pandas DataFrame. Here are the steps: Steps to Convert a NumPy Array to Pandas DataFrame Step 1: Create a NumPy Array For example, let’s create the following NumPy array that contains only numeric data (i.e., integers): Copy import numpy as np my_array … Read more