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

How to Convert Index to Column in Pandas DataFrame

You may use the following approach to convert index to column in Pandas DataFrame (with an “index” header): Copy df.reset_index(inplace=True) And if you want to rename the “index” header to a customized header, then use: Copy df.reset_index(inplace=True) df = df.rename(columns = {‘index’:’new column name’}) Later, you’ll also see how to convert MultiIndex to multiple columns. … Read more

Create a Table in SQL Server using Python

In this article, you’ll see how to create a table in SQL Server using Python. An example is also included for demonstration purposes. Steps to Create a Table in SQL Server using Python Step 1: Install the Pyodbc package If you haven’t already done so, install the Pyodbc package using this command: Copy pip install … Read more

Get a List of all Column Names in Pandas DataFrame

Here are two approaches to get a list of all the column names in Pandas DataFrame: (1) Using list(df) Copy my_list = list(df) (2) Using df.columns.values.tolist() Copy my_list = df.columns.values.tolist() The Example To start with a simple example, let’s create a DataFrame with 3 columns: Copy import pandas as pd data = {‘Name’: [‘Bill’, ‘Maria’, … Read more

How to Convert Integers to Datetime in Pandas DataFrame

Here is the syntax that you may use to convert integers to datetime in Pandas DataFrame: Copy df[‘DataFrame Column’] = pd.to_datetime(df[‘DataFrame Column’], format=specify your format) Note that the integers must match the format specified. Later, you’ll see several scenarios for different formats. Steps to Convert Integers to Datetime in Pandas DataFrame Step 1: Gather the … Read more

Set Column as Index in Pandas DataFrame

Two approaches to set a column as the index in Pandas DataFrame: (1) Set a single column as Index: Copy df.set_index(‘column’, inplace=True) (2) Set multiple columns as MultiIndex: Copy df.set_index([‘column_1’, ‘column_2′, …], inplace=True) Steps to Set Column as Index in Pandas DataFrame Step 1: Create a DataFrame To start with a simple example, let’s say … Read more

Convert Pandas Series to DataFrame

To convert your Series to a DataFrame: Copy df = ser.to_frame() Alternatively, you can use this approach to convert your Series: Copy df = pd.DataFrame(ser) Steps to Convert Pandas Series to DataFrame Step 1: Create a Series To start with a simple example, let’s create a Pandas Series from a List of 5 items: Copy … Read more

How to Download and Install R on Windows

In this short tutorial, you’ll see how to download and install R on Windows. You’ll also see how to run a simple script in R. Steps to Download and Install R on Windows Step 1: Download R To start, go to cran.r-project.org/bin/windows/base, and then click on the link to “Download R for Windows.” Step 2: … Read more

Categories R