Snippets Collections
# Create a virtual environment
python -m venv venv  # Windows
python3 -m venv venv  # MacOS/Linux

# Activate the virtual environment
venv\Scripts\activate  # Windows
source venv/bin/activate  # MacOS/Linux

# Install required packages
pip install kivy

# Create requirements.txt file
pip freeze > requirements.txt

# Run a test script
python test.py

--------------------------
in case of an POLICY error -- 
PS D:\Coding Stuff, Editing\Visual Studio Python Codings\MyProjects\BurgerBillingSystem> .\burger-billing-system-env\Scripts\activate     
.\burger-billing-system-env\Scripts\activate : File D:\Coding Stuff, Editing\Visual Studio Python 
Codings\MyProjects\BurgerBillingSystem\burger-billing-system-env\Scripts\Activate.ps1 cannot be loaded because running scripts is disabled on this system.     
For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ .\burger-billing-system-env\Scripts\activate
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

The error message you are encountering indicates that running scripts is disabled on your systems PowerShell execution policy. This is a security measure to prevent malicious scripts from running.

Here is how to fix this and activate your virtual environment:

Change the Execution Policy (For Administrators Only):

Open PowerShell as Administrator. "Right-click on the PowerShell" icon and select "Run as administrator".

Type the following command and press Enter:
"PowerShell Set-ExecutionPolicy RemoteSigned -Scope CurrentUser"

Activate the Virtual Environment (After Policy Change):
Navigate to your project directory using the cd command in PowerShell.
Run the activation command again:

---------------------------------
For Anaconda Jupyter Notebook -
pip install venv
python -m venv env_test
.\env_test\Scripts\activate
pip install ipykernel
python -m ipykernel install --user --name kernel_ai_cnn_1
Notebook Best Practices

Use Collapsible Headings and Table of Content
Notebooks should be executable from top to bottom
Name your variables carefully
Use dummy names such as tmp or _ when needed
Clear useless variables when not needed (del my_variable)
Clear your code and merge cells when relevant (Shift-M)
Hide your cell outputs to gain space (double-click on the red Out[]: section to the left of your cell).
from IPython.display import HTML, IFrame
IFrame("http://www.youtube.com/embed/8QiPFmIMxFc?t=388", width="560", height="315")
from ipywidgets import interact

@interact
def plot_polynom(a=[0,1,2,3], b=2):
    x = np.arange(-10, 10, 0.1)
    y = a*x**3+ b*x**2    
    plt.plot(x,y); plt.xlim(xmin=-10, xmax=10); plt.ylim(ymin=-100, ymax=100)
from ipywidgets import interact

@interact
def plot_polynom(a=[0,1,2,3], b=2):
    x = np.arange(-10, 10, 0.1)
    y = a*x**3+ b*x**2    
    plt.plot(x,y); plt.xlim(xmin=-10, xmax=10); plt.ylim(ymin=-100, ymax=100)
# Importing Libraries
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import seaborn as sns

# Dataprep for exploratory data analysis
from dataprep.eda import create_report
from dataprep.eda import plot, plot_correlation, plot_missing

# mport Regressor Metric Graph Plot - for ML analysis
from regressormetricgraphplot import *

# Set style to 'seaborn / Plot inline
plt.style.use('seaborn')
%matplotlib inline
%config InlineBackend.figure_format = 'retina'


# Load Dataframe
df = pd.read_csv('path/to/file.csv')
df.head()

df.isna().sum()
df.drop_duplicates(inplace = True)
df.info()
df.describe()

# Generate Dataprep Report
report = create_report(df, title='My Report')
create_report()

plot(df, col1, col2)

# df sortby
df.sort_values(by=[col1, col2], ascending=[True, True])

# df groupby
df.groupby(col).mean()
cat_type = CategoricalDtype(categories=['3', '2', '1'], ordered=True)
cat_type2 = CategoricalDtype(categories=['Kind','Jong','Middelbaar','Oud'], ordered=True)
​
df1['pclass'] = df1['pclass'].map({1: '1', 2: '2', 3: '3'})
df1['survived'] = df1['survived'].map({1: True, 0: False})
df1['sex'] = df1['sex'].map({'male': 'M', 'female': 'V'})
df1['pclass'] = df1['pclass'].astype(cat_type)
df1['sex'] = df1['sex'].astype('category')
df1['age'] = df1['age'].map(lambda x: round(x))
df1['age'] = df1['age'].astype('int8')
df1['fare'] = df1['fare'].map(lambda x: round(x, 2))
df1['age_cat'] = pd.cut(df1['age'], bins=4, labels=('Kind','Jong','Middelbaar','Oud'))
df1['age_cat'] = df1['age_cat'].astype(cat_type2)
df1 = df1.filter(items=['pclass', 'name', 'survived', 'sex', 'age', 'age_cat', 'fare'])
df1
<div style="background-color:rgb(250,250,250); padding:30px;box-shadow:0 1px 1px rgba(0, 0, 0, 0.2);">
    <p style="font-family:Helvetica;font-size:15px;font-weight:bold">
       Text....
    </p>
</div>
<div style="background-color:#1abc9c; padding:1px 20px 20px 20px; border-radius:5px;box-shadow: rgba(0, 0, 0, 0.25) 0px 0.0625em 0.0625em, rgba(0, 0, 0, 0.25) 0px 0.125em 0.5em, rgba(255, 255, 255, 0.1) 0px 0px 0px 1px inset;">
    <h1 style="font-family: 'Lato', sans-serif;color:white;padding-left:10px;font-size:50px">
        Heading
    </h1>
</div>

<div class="alert alert-block alert-info" style="border-radius:8px; box-shadow: rgba(0, 0, 0, 0.1) 0px 1px 3px 0px, rgba(0, 0, 0, 0.06) 0px 1px 2px 0px;">
    <b>&#9432; Note<br /></b> Use blue boxes (alert-info) for tips and notes.
    If it’s a note, you don’t have to include the word “Note”.
</div>
<div class="alert alert-block alert-warning" style="border-radius:8px; box-shadow: rgba(0, 0, 0, 0.1) 0px 1px 3px 0px, rgba(0, 0, 0, 0.06) 0px 1px 2px 0px;">
    <b>!&#x20DD; Important<br /></b> Use yellow boxes if you to underline important things.
</div>
<div class="alert alert-block alert-danger" style="border-radius:8px; box-shadow: rgba(0, 0, 0, 0.1) 0px 1px 3px 0px, rgba(0, 0, 0, 0.06) 0px 1px 2px 0px;">
    <b>&#9888; Warning<br /></b> In general, avoid the red boxes. These should only be
    used for actions that might cause data loss or another major issue.
</div>
<div class="alert alert-block alert-success" style="border-radius:8px; box-shadow: rgba(0, 0, 0, 0.1) 0px 1px 3px 0px, rgba(0, 0, 0, 0.06) 0px 1px 2px 0px;">
    <b>&#10149; See also<br /></b> Use green boxes to link to other documentation sources.
</div>
conda create -n my-conda-env                               # creates new virtual env
conda activate my-conda-env                                # activate environment in terminal
conda install ipykernel                                    # install Python kernel in new conda env
ipython kernel install --user --name=my-conda-env-kernel   # configure Jupyter to use Python kernel
jupyter notebook                                           # run jupyter from system
(firstEnv)
>>conda install -c anaconda ipykernel
>>python -m ipykernel install --user --name=firstEnv
#!/usr/bin/env python3

from multiprocessing import Pool

def run(task):
  # Do something with task here
    print("Handling {}".format(task))

if __name__ == "__main__":
  tasks = ['task1', 'task2', 'task3']
  # Create a pool of specific number of CPUs
  p = Pool(len(tasks))
  # Start each task within the pool
  p.map(run, tasks)
# this line will write the code below into a Python script called script.py
%%writefile script.py
star

Thu Jun 13 2024 08:24:06 GMT+0000 (Coordinated Universal Time) https://www.google.com/search?q

#python #env #kernel #jupyter #anaconda
star

Sat Nov 26 2022 10:37:00 GMT+0000 (Coordinated Universal Time)

#jupyter
star

Sat Nov 26 2022 10:31:55 GMT+0000 (Coordinated Universal Time)

#jupyter
star

Sat Nov 26 2022 10:31:08 GMT+0000 (Coordinated Universal Time)

#decorators #jupyter
star

Sat Nov 26 2022 10:31:06 GMT+0000 (Coordinated Universal Time)

#decorators #jupyter
star

Sat Oct 29 2022 22:51:37 GMT+0000 (Coordinated Universal Time)

#plot #jupyter #template
star

Wed Aug 10 2022 05:32:42 GMT+0000 (Coordinated Universal Time) http://localhost:8888/notebooks/titanic.ipynb

#jupyter #notebook #titanic #dataset
star

Thu Dec 09 2021 09:47:17 GMT+0000 (Coordinated Universal Time)

#jupyter #markdown
star

Thu Dec 09 2021 09:46:17 GMT+0000 (Coordinated Universal Time)

#jupyter #markdown
star

Wed Nov 10 2021 10:32:25 GMT+0000 (Coordinated Universal Time)

#html #jupyter #markdown
star

Wed Nov 10 2021 10:32:00 GMT+0000 (Coordinated Universal Time)

#html #jupyter #markdown
star

Wed Nov 10 2021 10:31:18 GMT+0000 (Coordinated Universal Time)

#html #jupyter #markdown
star

Wed Nov 10 2021 10:30:02 GMT+0000 (Coordinated Universal Time)

#html #jupyter #markdown
star

Wed May 12 2021 00:33:13 GMT+0000 (Coordinated Universal Time)

#jupyter #anaconda
star

Tue Apr 06 2021 19:57:21 GMT+0000 (Coordinated Universal Time)

#python #conda #jupyter
star

Fri Apr 02 2021 06:41:25 GMT+0000 (Coordinated Universal Time)

#python #jupyter
star

Tue Mar 30 2021 18:52:27 GMT+0000 (Coordinated Universal Time)

#python #jupyter

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension