home
arrow_upward

Python

My notes

Python special features

Thing I find interesting about Python.



Tools to practise:



Setup and frequently used commands

To set up a Python virtual environment:
python3 -m venv ~/.venv

You can also use:
virtualenv  ~/.venv

To find location of the Python version in use:
which python



Fantastic Python reference material

Building a microservice and hosting on AWS (Python, FastAPI)

Study of data structures in Python

Studied python data structures to some depth as part of the AI MLOps course at IISc. Python datatypes studied - list, dict, tuples, set, sequences.





Notes on Python's List sequence type

Used for similar datatypes. Can add or remove items easily.



Notes on Python's Dictionary data structure type

Used for storing key-value pairs.



Pandas

A library that makes it easy to read, write data stored in different file formats and manipulate it in bulk. This is a favorite for CSVs. A great place to learn the basics of Pandas is The gentle introduction to pandas by Rob Mulla. The two main structures that pandas works on are called Series and Dataframes.

Example of initializing a Series

#
import pandas as pd    

pups = ['pitbull', 'german shepard','french bulldog']   
myseries = pd.Series(pups)  
print(myseries) 
#

Output

.
0    pitbull    
1    german shepard   
2    french bulldog   
dtype: object   
.



Example of initializing a Dataframe

#
import pandas as pd 

pups = [('tyson', 'pitbull',72), ('tommy', 'labrador', 2)]     
myseries = pd.DataFrame(pups, columns=['Name', 'Breed', 'Age'])   
print(myseries) 
#

Output

.
    Name     Breed  Age    
0  tyson   pitbull   72    
1  tommy  labrador    2 
.


The column name argument is optional. Defaults to 0,1,2.. if not specified. The first column (numbers) is the index automatically assigned by the Series/Dataframe.



Collab tricks

Some keyboard shortcuts and tricks to improve your google collab experience.