Cheat Sheet
Python
General Python
Basics
import(package) from x import y print(x) package.function(x) # comment input("prompt") "string" 'string' variable = int(x) float(x) '''comment'''
Conditionals, Loops, Functions, and Lists
if condition:
do stuff
elif condition:
do stuff
else:
do stuff
break
while condition:
do stuff
for x in range(y):
do stuff
my_list = ['thing', 1, 'another thing']
my_list.append('add something to the end')
my_list.insert(0)
my_list.pop(0)
my_list.remove(0)
for x in my_list:
do x
def my_function(argument):
do something(argument)
Turtle
s = turtle.getscreen() t = turtle.Turtle()
Data Analysis
open('filename.extension') .readline() .read() list(list_name.split(seperating_character)) %matplotlib inline plt.plot(x,y,'options') plt.show() plt.bar(x,y) plt.title("Title") plt.xlabel('x axis label') plt.ylabel('y axis label') my_dataframe = pd.read_csv('filename.csv', index_col="Index Column Name") my_dataframe.describe() my_dataframe.info() my_dataframe[x:y][['column name(s)']] my_dataframe.max() my_dataframe['column name'].max() my_dataframe.columns my_dataframe.values my_dataframe.sort_values('column name')
Command line
$ ls $ ls -a $ dir $ dir -a $ cd directory_name $ cd - $ cd $ cat filename $ python3 filename.py $ nano filename.py $ clear $ "press the up arrow key to find the last command you ran" $ exit
Markdown
Text formatting
# H1 ## H2 ### H3 #### H4 ##### H5 ###### H6 bold italicise ---
Tables
Col A | Col B | Col C --- | --- | --- apple | Boy | Mac
rendering