Tutorials
Introduction
In this tutorial, we will learn how to change the file path for the output dataset generated by the Spacewalk software. By the end of this tutorial, you will be able to specify a custom file path for the cleaned dataset.
Prerequisites
Before you start, ensure you have the following:
- Python installed on your system
- The Spacewalk script (
eva_data_analysis.py) - An input dataset (
eva-data.json)
Prepare the destination directory
First, let us decide where we want to save the cleaned dataset and make sure the directory exists.
For this tutorial, we will use data/clean/ as the destination folder.
Let's create the directory if it does not exist - e.g. from the command line do:
mkdir -p data/clean
Run the analysis script with a custom path
Next, execute the Spacewalk script and specify the custom file path for the output dataset:
(venv_spacewalks) $ python3 eva_data_analysis.py <input-file> <output-file>
Replace with your input dataset (data/eva-data.json) and with your desired output path (data/clean/eva-data-clean.csv).
Here is the complete command:
(venv_spacewalks) $ python3 eva_data_analysis.py data/eva-data.json data/clean/eva-data-clean.csv
Notice how the output to the command line clearly indicates that we are using a custom output file path.
Using custom input and output filenames
Reading JSON file data/eva-data.json
Saving to CSV file data/clean/eva-data-clean.csv
Adding crew size variable (crew_size) to dataset
Saving to CSV file data/clean/eva-data-clean.csv
Plotting cumulative spacewalk duration and saving to results/cumulative_eva_graph.png
After running the script, let us check the data/clean directory to ensure the cleaned dataset has been saved correctly.
(venv_spacewalks) $ ls data/clean
You should see eva-data-clean.csv file listed in the data/clean folder.
Exercise: custom output path
- Create a new directory named output/data in your working directory.
- Run the Spacewalk script to save the cleaned dataset in the newly created output/data directory with the filename cleaned-eva-data.csv.
- Verify that the dataset has been saved correctly.
Solution
# Create the directory:
(venv_spacewalks) $ mkdir -p output/data
# Run the script:
(venv_spacewalks) $ python3 eva_data_analysis.py data/eva-data.json output/data/cleaned-eva-data.csv
# Verify the output:
(venv_spacewalks) $ ls output/data
# You should see cleaned-eva-data.csv listed
Congratulations! You have successfully changed the file path for Spacewalks output dataset and completed an exercise to practice the process. You can now customize the output location and filename according to your needs.