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 sysprint(sys.version) Here is an example of a version of the Python Interpreter: Get the components of your version If you want to get the components of your version, you may use: Copy import sysprint(sys.version_info) For our example, … 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_new_list = [“new item” if i == “old item” else i for i in my_list] In this guide, you’ll see 3 cases of: The Example To start with a simple example, create the … Read more

Replace Characters in Strings in Pandas DataFrame

Here are 2 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 an entire DataFrame: Copy df = df.replace(“old character”, “new character”, regex=True) Examples Example 1: Replace a Specific Character under a Single DataFrame … Read more

How to Control a Mouse using Python

The PyAutoGUI library can be used to control a mouse in Python. To install the PyAutoGUI library: Copy pip install pyautogui Next, you’ll see 4 scenarios to control a mouse in Python by: 4 Scenarios of Controlling a Mouse using Python Scenario 1: Moving a mouse cursor to a specific location To move a mouse … 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

How to Convert Pandas DataFrame to NumPy Array

Here are two approaches to convert Pandas DataFrame to a NumPy array: (1) First approach: Copy df.to_numpy() (2) Second approach: Copy df.values Steps to Convert Pandas DataFrame to a NumPy Array Step 1: Create a DataFrame To start with a simple example, let’s create a DataFrame with 3 columns. The 3 columns will contain only … Read more

Delete Records in SQL Server using Python

In this guide, you’ll see how to delete records in SQL Server directly from Python. Here are the steps that you may follow. Steps to Delete Records in SQL Server using Python Step 1: Install the Pyodbc Library If you haven’t already done so, install the pyodbc library using the following command: Copy pip install … Read more

Select all Rows with NaN Values in Pandas DataFrame

Here are 4 ways to select all rows with NaN values in Pandas DataFrame: (1) Using isna() to select all rows with NaN under a single DataFrame column: Copy df[df[‘column name’].isna()] (2) Using isnull() to select all rows with NaN under a single DataFrame column: Copy df[df[‘column name’].isnull()] (3) Using isna() to select all rows … Read more