Add Suffix to Each Column Name in Pandas DataFrame

To add a suffix to each column name in Pandas DataFrame: Copy df = df.add_suffix(‘your suffix’) Steps to Add Suffix to Each Column Name in Pandas DataFrame Step 1: Create a DataFrame To start with a simple example, let’s say that you have the following dataset that contains 3 columns: Product Price Discount ABC 750 … Read more

How to Concatenate Two Lists in Python (with examples)

You can use either of the following templates in order to concatenate two lists in Python: (1) Using the + operator: Copy list_one = [‘item1’, ‘item2’, ‘item3’, ….] list_two = [‘item1’, ‘item2’, ‘item3’, ….] concatenated_list = list_one + list_two print(concatenated_list) (2) Using extend: Copy list_one = [‘item1’, ‘item2’, ‘item3’, ….] list_two = [‘item1’, ‘item2’, ‘item3’, … Read more

Generate Random Numbers in a Python List

Here are 2 ways to generate random numbers in a Python list: (1) Generate random numbers that cannot be repeated: Copy import randommy_list = random.sample(range(lowest number, highest number), number of items in the list)print(my_list) For example, let’s generate 15 random numbers, where the lowest number is 1 (inclusive), while the highest number is 30 (exclusive): … Read more

Add Prefix to Each Column Name in Pandas DataFrame

To add a prefix to each column name in Pandas DataFrame: Copy df = df.add_prefix(‘my_prefix’) Steps to Add Prefix to Each Column Name in Pandas DataFrame Step 1: Create a DataFrame To start with a simple example, let’s suppose that you have the following dataset with 3 columns: Product Price Discount ABC 750 Yes DDD … Read more

Check the Scikit-Learn Version Installed

You can check the Scikit-Learn version installed using this syntax: Copy import sklearn print(sklearn.__version__) Run the code in Python, and you’ll get the version of Scikit-Learn. Here is an example of the version installed that you may get: Check the version installed using the command line You can also check the Scikit-Learn version installed using … Read more

Change Strings to Lowercase in Pandas DataFrame

To change strings to lowercase in Pandas DataFrame: Copy df[‘column name’] = df[‘column name’].str.lower() Steps to Change Strings to Lowercase in Pandas DataFrame Step 1: Create a DataFrame To begin, create a simple DataFrame with 5 fruits (all in uppercase) and their prices: Copy import pandas as pd data = {‘Fruits’: [‘BANANA’, ‘APPLE’, ‘MANGO’, ‘WATERMELON’, … Read more

Create a Bar Chart in Python using Matplotlib

To create a bar chart in Python using Matplotlib: Copy import matplotlib.pyplot as pltx_axis = [“value_1”, “value_2”, “value_3”, …]y_axis = [“value_1”, “value_2”, “value_3”, …]plt.bar(x_axis, y_axis)plt.title(“title name”)plt.xlabel(“x_axis name”)plt.ylabel(“y_axis name”)plt.show() Steps to Create a Bar Chart in Python using Matplotlib Step 1: Install the Matplotlib package If you haven’t already done so, install the Matplotlib package using … Read more

Select Rows Containing a Substring in Pandas DataFrame

In this guide, you’ll see how to select rows that contain a specific substring in Pandas DataFrame. In particular, you’ll observe 5 scenarios to get all rows that: Contain a specific substring Contain one substring OR another substring Do NOT contain given substrings Contain specific substring in the middle of a string Contain a specific … Read more

Drop a Table in SQL Server using Python

In this short guide, you’ll see how to drop a table in SQL Server using Python. Example is also included for illustration purposes. Steps to Drop a Table in SQL Server using Python Step 1: Install the Pyodbc package The Pyodbc package can be used to connect Python to SQL Server. If you haven’t already … Read more

Create a Scatter Diagram in Python using Matplotlib

To create a scatter diagram in Python using Matplotlib: Copy import matplotlib.pyplot as pltx_axis = [“value_1”, “value_2”, “value_3”, …]y_axis = [“value_1”, “value_2”, “value_3”, …]plt.scatter(x_axis, y_axis)plt.title(“title name”)plt.xlabel(“x_axis name”)plt.ylabel(“y_axis name”)plt.show() Steps to Create a Scatter Diagram in Python using Matplotlib Step 1: Install the Matplotlib package If you haven’t already done so, install Matplotlib using the following … Read more