How to Run Python Scripts Involving Pandas via PowerShell
![](/images/blog/how-to-blog5.webp)
As a data scientist or a software engineer working with data, you may find yourself needing to run Python scripts that involve the use of Pandas library. While running Python scripts is relatively easy, running scripts with dependencies like Pandas can be challenging, especially if you are using Windows operating system. In this post, we will guide you on how to run Python scripts that involve Pandas via PowerShell.
Table of Contents
- Introduction
- What is PowerShell?
- Step 1: Install Python and Pandas
- Step 2: Set Up PowerShell Execution Policy
- Step 3: Create a Python Script
- Step 4: Run the Python Script in PowerShell
- Conclusion
What is PowerShell?
PowerShell is a command-line shell and scripting language developed by Microsoft. It is designed to automate administrative tasks and provide an interactive command-line interface for Windows operating systems. PowerShell allows you to run commands, execute scripts, and automate tasks using a simple syntax.
Step 1: Install Python and Pandas
Before running Python scripts that involve Pandas via PowerShell, you need to have Python and Pandas installed on your computer. You can download and install Python and Pandas from the official websites:
Once you have downloaded and installed Python and Pandas, you can proceed to the next step.
Step 2: Set Up PowerShell Execution Policy
By default, PowerShell restricts the execution of scripts on Windows operating systems. Therefore, you need to change the execution policy to allow the execution of scripts. To do this, follow these steps:
Open PowerShell as an administrator.
Type the following command and press Enter:
Set-ExecutionPolicy Unrestricted
Step 3: Create a Python Script
Next, you need to create a Python script that involves Pandas. For the purposes of this tutorial, we will create a simple Python script that loads a CSV file using Pandas and displays the contents:
import pandas as pd
data = pd.read_csv("D:\SamNewLocation\Desktop\dat.csv", delimiter=';')
print(data)
Save the script as script.py
in a directory of your choice.
Step 4: Run the Python Script in PowerShell
Now that you have set up PowerShell and created a Python script, you can proceed to run the script in PowerShell. To do this, follow these steps:
Open PowerShell as an administrator.
Navigate to the directory where you saved the
script.py
file. You can do this by typing the following command and pressing Enter:cd "C:\Users\Ing. PierreLouis\OneDrive\Documents"
Replace
C:\Users\Ing. PierreLouis\OneDrive\Documents
with the actual path to the directory where you saved thescript.py
file.Type the following command and press Enter to run the Python script:
python script.py
This command will execute the Python script and display the contents of the CSV file.
Conclusion
In conclusion, running Python scripts that involve Pandas via PowerShell is relatively easy once you have Python and Pandas installed and have set up PowerShell execution policy. By following the steps outlined in this tutorial, you should be able to run Python scripts that involve Pandas on your Windows computer using PowerShell.
About Saturn Cloud
Saturn Cloud is your all-in-one solution for data science & ML development, deployment, and data pipelines in the cloud. Spin up a notebook with 4TB of RAM, add a GPU, connect to a distributed cluster of workers, and more. Request a demo today to learn more.
Saturn Cloud provides customizable, ready-to-use cloud environments for collaborative data teams.
Try Saturn Cloud and join thousands of users moving to the cloud without
having to switch tools.