Import a CSV File to SQL Server using Python

In this guide, you’ll see a simple technique to import a CSV file to SQL Server using Python. Here are the steps: Steps to Import a CSV file to SQL Server using Python Step 1: Prepare the CSV File To begin, let’s prepare a CSV file called ‘products’ with the following data: product_id product_name price … Read more

Fastest way to Convert Integers to Strings in Pandas DataFrame

In this article, we’ll examine the fastest way to convert integers to strings in Pandas DataFrame. The approaches that will be measured are: (1) map(str) Copy df[“DataFrame Column”] = df[“DataFrame Column”].map(str) (2) apply(str) Copy df[“DataFrame Column”] = df[“DataFrame Column”].apply(str) (3) astype(str) Copy df[“DataFrame Column”] = df[“DataFrame Column”].astype(str) (4) values.astype(str) Copy df[“DataFrame Column”] = df[“DataFrame Column”].values.astype(str) … Read more

Check for NaN in Pandas DataFrame

Here are 4 ways to check for NaN in Pandas DataFrame: (1) Check for NaN under a single DataFrame column: Copy df[‘column name’].isnull().values.any() (2) Count the NaN under a single DataFrame column: Copy df[‘column name’].isnull().sum() (3) Check for NaN under an entire DataFrame: Copy df.isnull().values.any() (4) Count the NaN under an entire DataFrame: Copy df.isnull().sum().sum() … Read more

Generate Random Integers in Pandas Dataframe

In this short guide, you’ll see how to generate random integers in Pandas DataFrame under: You’ll also see how to convert those integers to different data types, such as floats or strings. Generate Random Integers under a Single DataFrame Column Here is a template that you may use to generate random integers under a single … Read more

How to Create a Time Delay in Python

You may use the time module in order to create a time delay in Python: Copy import time time.sleep(number of seconds of delay) Here are few examples of time delays: 3 seconds time delay: Copy import time time.sleep(3) 3 minutes time delay: Copy import time time.sleep(3 * 60) 3 hours time delay: Copy import time … Read more

How to Create a Progress Bar in Python

In this short guide, you’ll see how to create a progress bar in Python using the tqdm package. You’ll also observe how to add a GUI to track your progress. Steps to Create a Progress Bar in Python Step 1: Install the tqdm package To begin, install the tqdm package using this command: Copy pip … Read more

How to apply an input() function in Python

To apply an input function in Python: Copy value = input() Next, you’ll see 3 examples of an input function: 3 Examples of an Input Function in Python Example 1: input function for a text/string You can utilize an input function in order to gather text from users. For example, the following syntax can be … Read more

Convert Text File to CSV using Python

To convert a text file to a CSV file using Python: Copy import pandas as pd read_file = pd.read_csv(r”Path where the Text file is stored\File name.txt”) read_file.to_csv(r”Path where the CSV will be saved\File name.csv”, index=False) Steps to Convert a Text File to CSV using Python Step 1: Install the Pandas package If you haven’t already … Read more

Convert CSV to JSON using Python

To convert a CSV file to a JSON file using Python: Copy import pandas as pddf = pd.read_csv(r”Path where the CSV file is saved\File Name.csv”)df.to_json(r”Path where the new JSON file will be stored\New File Name.json”) Steps to Convert CSV to JSON using Python Step 1: Prepare the CSV File To start, prepare a CSV file … Read more