Show Menu
Cheatography

Python 3 - Intermediate for Data Cheat Sheet (DRAFT) by

Focus on scripting for data. Reference to what I personally forget syntax on.

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Syntax, Oh How You've Changed

Comments
Case-s­ens­itive
' versus "
Tomato, Toma-to
Escape
\,
'Admiral Hopper\'s Great!'
Test
if:
elif:
else:
Catch Errors
try {} else {}
Loops
for hero in sheros:
,
while cops > 0:
Functions
def inclus­ion­(ax­is_­of_­opp­res­sion, status­=True):

Strings, Please Don't Make Spaghetti

.count­('Ada')
Ada is in the list X times
.repla­ce(­'he­t',­'qu­eer')
history to future
.strip()
whites­pace, not your t-shirt
"My {0} used {1}.".f­orm­at(­"­Mom­"­,"punch cards")

List, I will finish you

Order
.sort(key=len, revers­e=True)
Z to A.
len
is f(x)
.sorted()
for any iterable
Subset
kids[1:3]
get index 1 & 2 (Slice)
List Math
mylist + mylist
==
mylist * 2
Contains?
'asexual' in sexual­_or­ien­tations
From the end
mylist[-2]
CRUD
.append()
, __, __,
.pop()
Nest
family­[0][0]
get Drag Grandchild

Dictio­naries, Let's Get Real

>>> words = {'white supremacy': 'systemic racism',
    'patriarchy': 'sexism'}
>>> words.keys()
dict_keys(['white supremacy', 'patriarchy'])
>>> words.values()
dict_values(['systemic racism', 'sexism'])

Compare & Contrast, A Non-Essay

Even?
10 % 2
is 0, so True
Contains Element
Contains Sub-string
 

Data Libraries, Dewey to my CSVs

import numpy as np
import pandas as pd