.png)
Tutorial to get you started with Python pandas and CSV files using pd.read_csv()
TL;DR: If you’re comfortable with the Terminal and the command line, you can simply save a file as a “.py” file and run the script using “python your_file.py”. Alternatively, if you want to start even simpler, you can simply log in to Fabi.ai and copy/paste the script in a Python cell or ask ChatGPT to run the code for you.
Running a Python script is one of the most fundamental tasks every programmer must learn, but you may also have been given a Python script from a coworker or AI and trying to figure out what to do with it.. Whether you’re a beginner writing your first program or an experienced developer looking for a convenient execution method, knowing different ways to run a Python script can save you time and effort.
This guide will walk you through three different ways to run a Python script:
Each method has its own advantages and use cases, and by the end of this guide, you'll know which one is best suited for your needs.
For the visual learners, we have a video that walks you through each example:
The command line (also called the terminal in macOS/Linux or Command Prompt/PowerShell in Windows) is one of the most common and powerful ways to run Python scripts. This method is widely used by developers, especially when working on larger projects, automation scripts, or server-side applications.
Before running a Python script, you need to create one.
Open a text editor like Notepad (Windows), TextEdit (Mac), VS Code, or Sublime Text.
Copy and paste the following code:
print("Hello, World!")
Save the file as hello.py.
Make sure the file extension is .py, which tells the system that it’s a Python script.
To run the script, search for Terminal or PowerShell and open the program:
The command line starts in your home directory, so you need to navigate to the folder where your script is saved.
Use these commands:
Check your current directory
pwd # (macOS/Linux)
echo %cd% # (Windows)
Change directory (cd) to your script’s location
cd path/to/your/folder
For example, if your script is in the "Documents" folder:
cd Documents
List files in the directory
ls # (macOS/Linux)
dir # (Windows)
Once you’re in the correct directory, type the following command:
python hello.py
You should see the output:
Hello, World!
If your system doesn’t recognize the python command, you may need to install Python.
Verify the installation by running:
python --version
💡 Command line pros: Best for developers, automation, and large-scale projects.
⚠️ Command line cons: Requires setup, typing commands manually, and familiarity with basic shell commands.
If you just want to test out a Python script without installing anything, ChatGPT can be a quick way to run simple Python code online.
Simply type:
Run the following Python script:
Then paste your Python code inside triple single quotes ('''):
'''print("Hello, World!")'''
ChatGPT will process and execute the script, then return the output.
To ensure that ChatGPT is truly running the script and not just interpreting the text, you can ask it to generate and execute a more complex script:
import matplotlib.pyplot as plt
import numpy as np
# Generate fake data
x = np.arange(10)
y = np.random.randint(1, 100, 10)
# Plot the data
plt.plot(x, y, marker='o')
plt.title("Random Data Plot")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.show()
If ChatGPT successfully plots the data, it confirms that it can run more than just basic print statements.
💡 ChatGPT pros: Quick, easy, and no installation required.
⚠️ ChatGPT cons: Limited capabilities; cannot handle advanced projects.
Fabi.ai is an AI-powered coding platform that allows you to write, execute, and debug Python scripts in your browser—without installing anything!
Once logged in, you can write Python code directly in Fabi.ai’s editor.
For example, to print "Hello, World!" in Fabi.ai:
print("Hello, World!")
Hit the Run Code button, and Fabi.ai will execute the script instantly.
If you want to analyze a dataset:
import pandas as pd
# Create a sample DataFrame
data = {
'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 30, 35],
'Salary': [50000, 60000, 70000]
}
df = pd.DataFrame(data)
# Display the DataFrame
print(df)
Fabi.ai will execute the script, display the DataFrame, and even provide AI-powered suggestions for further analysis.
💡 Fabi.ai pros: Beginner-friendly, fast, and AI-assisted debugging.
⚠️ Fabi.ai cons: Best suited for enterprise
Sign up for free to get started with Fabi.ai in less than 2 minutes!