-n ds conda create
Setting up a minimal data-science environment in Windows using WSL (part II)
Set up a conda environment for data-science
Now that we have conda installed, let us set up a conda environment called ds
(for data-science). Open WSL, then run
Activate the environment:
conda activate ds
When you now run python3
, it will launch the version of the python interpreter that came with anaconda (in the previous step), not the version that comes pre-installed with WSL.
You can now install the following basic data-science packages:
-learn pandas Jupyter conda install numpy scipy matplotlib seaborn scikit
Conda official repository only feature a few verified packages. A vast portion of python packages that are otherwise available through pip are installed through community led channel called conda-forge. You can visit their site to learn more about it. To do this, install your other packages package1
and package2
(say), by specifying the conda-forge
channel :
-c conda-forge package1 package2 conda install
Test your installation:
We now test the installation by using the following workflow:
- Create a python script using the Windows text editor of your choice, save it in your
~/Downloads
folder. - Execute the script from Bash.
Create a new file called test.py
in ~/Downloads
with the following content:
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from scipy import stats
# Generate some random data
42)
np.random.seed(= np.random.normal(size=100)
x = np.random.normal(size=100)
y
# Create a DataFrame from the data
= pd.DataFrame({'x': x, 'y': y})
df
# Plot a scatter plot using Seaborn
=df, x='x', y='y')
sns.scatterplot(data
# Add a regression line using SciPy
= stats.linregress(x, y)
slope, intercept, r_value, p_value, std_err * x + intercept, color='red')
plt.plot(x, slope
# Set the x and y labels using Matplotlib
'X')
plt.xlabel('Y')
plt.ylabel(
# Show the plot
plt.show()
and run it with
~/Downloads/test.py python3