Python Basics – Comparison Operators

Comparison Operators Equality :  == , != Order: < , > , <= , >= Assignment Operator Assignment : =   13 == 13 > True count = 13 print(count) > 13 Equality Comparisons datetimes numbers ( float / int ) dictionaries strings … # Comparing dictionaries d1 = {‘high’:56.78,’low’:33.24,’closing’:56.77} d2 = {‘high’:56.78,’low’:33.24,’closing’:56.77} print(d1 == […]

Python Basics – Dictionary

Dictionaries Lists my_list = [‘a’,’b’,’c’,’d’] # index 0 1 2 3 my_list[0] > ‘a’ my_list.index[‘c’] > 2 Intro Keys Values —- —— Firm Code FRD Process Date 10/14/2019 CUSIP 13246879 Representation of a dictionary =  { ‘key-1’ : ‘value-1’ , ‘key-2’ : ‘value-2’ , ‘key-3’ : ‘value-3’ , ‘key-4’ : ‘value-4’  } Creation # Create […]

Python Basics – Datetime

Datetimes – basic Datetime from datetime import datetime black_monday = datetim(1987, 10, 19) > datetime.datetime(1987, 10, 19, 0, 0) Current Datetime from datetime import datetime datetime.now() Datetime from a string black_monday_str = “Monday, October 19, 1987, 9:30 am” format_str = “%A, %B %d, %Y, %I:%M %p” datetime.datetime.strptime(black_monday_str, format_str) > datetime.datetime(1987, 10, 19, 9, 30) Year: […]

Python – Machine Learnining Code Snippets

Feature Engineering Skewed Distribution You’ve been fine-tuning a machine learning model you created for predicting mortgage defaults on a mortgages DataFrame. You’re aiming to eliminate skewness from your numerical variables by using a log transformation. Despite the transformation, one of your columns is still skewed – why do you think so and what is the […]

Python Code Snippets – Import and Cleaning

Importing and Cleaning Importing Pickle-files import pandas as pd x = pd.read_pickle(‘data.pkl’) CSV Files # Use only certain columns import pandas as pd cols= [‘style’, ‘type’, ‘price’] wine= pd.read_csv(file_name, usecols= cols) print(wine.head()) # – values in the CSV are replaced by NaN import pandas as pd candy= pd.read_csv(file_name, na_values= ‘-‘) print(candy.head()) TXT Files data = […]

SQL Code Snippers

SQL – PostgreSQL Aggregation – Basic SELECT DISTINCT naam FROM steden WHERE LEFT(stadsnaam, 1) IN (‘A’,’B’,’C’,’D’,’E’) ORDER BY stadsnaam SELECT COUNT(*) FROM batsman_scored WHERE batsman_scored.runs_scored = 6; SELECT COUNT(DISTINCT(nationality)) FROM athletes ; SELECT item, CASE WHEN energy > 300 THEN ‘high’ WHEN energy > 150 THEN ‘medium’ ELSE ‘low’ END AS calorie_rating FROM food ORDER […]

Python Code – Basic Programming

Lists packages = [‘numpy’,’pandas’,’scipy’] for i in packages:   print(i) import pandas as pd list_keys = [‘a’,’b’] list_values = [[‘x’,’y’],[1,2]] all = list(zip(list_keys, list_values)) > all > [(‘a’,[‘x’,’y’]),(‘b’,[1,2])] [i for i in range(5) if i > 2] > [3, 4] [s.upper() for s in [‘hallo’,’aarde’]] > [‘HALLO’,’AARDE’]   Dictionaries d = { ‘appel’: 1, ‘peer’: […]

Eisenhower Matrix

Eisenhower Matrix The 4 blocks : FOCUS (Green) : Important & Urgent / daily Focus Tasks–> Picking one task that is the most important and do that task first & immediately SCHEDULE (Blue) : Important & Not Urgent / Maintenance –> The help to help on long term. These are tasks to be scheduled to […]