SlideShare a Scribd company logo
1 of 2
Download to read offline
PYTHON 3
CHEET SHEET BY @CHARLSTOWN
CREATOR: GUIDO VAN ROSSUM
YEAR: 1991
LATEST VERSION (2019): 3.7.4
TOP LIBRARIES: TENSORFLOW, SCIKIT-LEARN,
NUMPY, KERAS, PYTORCH, PANDAS, SCIPY
STRING OPERATORS “Hello world”
ELEMENTAL LIBRARIES import *
INT/FLOAT OPERATORS 3 + 2.56
LIST OPERATORS [“A”, “B”, 5, True]
DICT. OPERATORS {ky1: “A”, ky2: list}
TIMING THE CODE
LOOPS
FUNCTION & LAMBDA:
LIST & DICT COMPREHENSIONS
str(29)			 > Int/Float to string
len(“string”)			 > Total string length
“My” + “age is:” + “28” > Sum strings
“Hey!” * 3			 > Repeat string by 3
“a“ in “chartlstown“		 > True if str in str
‘letters‘.isalpha()		 > Check only letters
‘string’.upper()			 > STR to CAPS-CASE
‘string‘.lower()			 > STR to lower-case
‘string‘.title()			 > First letter to CAPS
list(“string“)			 > Letters to list
‘my string‘.split()		 > Words to List
““.join(list)			 > List to String by ““
“AB“.replace(“A”, “B”) > Replace AB > BB
string.find(“A”) > Index from match
“ A “.strip()			 > No leading spaces
f”My age: {28}”			 > Insert in string
“”My age: {}”.format(28) > Old insert in string
“AB”CD”			 > Include symbol “
“n”				 > New line in string
“t”				 > Tabulator in string
var = input(‘question?’) >Input string form
import lib			 > Import all from lib
from lib import function > Import function I
lib.function()			 > Import function II
dir(math)			 > Show all functions
import library as lb		 >Library shortcut
int(“25“)			 > String to integer
type()			 > Returns type
A//B				 > Returns ratio
A&B				 > Returns reminder
divmod(A, B)			 > Ratio/reminder
len()				 > Returns lenght
max() > Max. value
min()			 > Min. value
abs()				 > Absolute value
pow(5, 2)				 > 5 powered by 2
5**2					 > 5 powered by 2
round(A, 3)			 > Round 3 decimals
sum(list)				 > Sum all list items
len(list)			 > Count items in list
list(range(0,10,2))		 > List from range
list.reverse()			 > Reverse the list
lst[idx] > Element index
lst[idx] = “item” > Change item
lst.append(‘item’)		 > Add item
lst[-5:] > Slicing list
list.index(“B”) > Position index
list.insert(0, A) > Insert item by index
list.remove(5)			 > Remove element
list.count(A)			 > A frequency
list.sort()			 > Sort in same list
sorted(lst)			 > Sort in new list
lst.pop()			 > Last item
list(zip(lst_1, lst_2))		 > Entwine pair of lists
enumerate(list) > Add index to list
dic[key] = val > Add a key
dic.update({ky: v, ky: v}) > Add multiple keys
dic[key] = val > Overwrites value
dic[key] > Extracts a value I
dic.get(key) > Extracts a value II
dic.get(key, DefVal) > Extracts a value III
dic.pop(key)			 > Delete K and V I
del dic[k] > Delete K and V II
dic.keys()			 > Keys List
dic.values()			 > Values list
dic.items()			 > Returns K and V
key in dict			 > Checks key
dict(zip(lst_1, lst_2))		 > Pair lists to Dict.
time.time()			 > Get elapsed time
time.sleep(s)			 > Pause code s secs.
time.localtime()		 > Get local time
for item in list:			 > for loop
print(item)		 > Iterate by items
while limit <= 5:		 > while loop
limit += 1			 > Iterate by condition
def switch(in1, in 2):		 > Code as function
return (in2, in1) > Switch variables
switch(“a”, “b”)			 > Run function on a,b
plus_one = lambda x: x+1> Code as expression
plus_one(5)			 > Number plus 1
LIST COMPREHENSION
lst_A = [i for i in lst_B if i < 0]
LIST COMPREHENSION NESTED
lst_A = [i if i < 0 else i-5 for i in lst_B]
LIST COMPREHENSION NESTED
lst_A = [[i+1 for i in x] for x in lst_B]
DICT COMPREHENSION
{key: value for key, value in dict.items()}
BASIC FUNCTIONS import numpy as np DATA FRAMES import pandas as pd
EXTRACTING COLUMNS AND ROWS
PANDAS AGGREGATES (COMANDS)
P.A. (GROOPING)
MERGE METHODS
ADD AND RENAME COLUMNS
SORTING METHODS
APPLY MODIFICATIONS & LAMBDA
MATRIX		 import numpy as np
NUMPY_LIBRARY PANDAS_LIBRARY
IMPORTING CSV FILES:
np.getfromtxt(‘f.csv’, delimiter = ‘,’)
- - - - - - - - - - - - - - - - - - - -
np.mean(lst)			>> Average
np.sort(lst)			 >> Sort the list
np.median(lst)			>> Median
np.percentile(lst, n)		 >> Percentil n%
np.std(lst)			 >> Standard devi.
np.mean(mtx < n) >> Conditions
np.var()			>> Variance
IMPORTING CSV FILES:
pd.read_csv(‘f.csv’)
- - - - - - - - - - - - - - - - - - - -
pd.DataFrame(Dict)		 >> Create a DF I
columns = [list] >> Create a DF II
- - - - - - - - - - - - - - - - - - - -
df.head(n) >> shows first n rows
df.info()			 >> entries and data
df.column.values >> Extract column
df[‘colum’] >> Extract multiple clmns
df[[c1, c2]] >> Extracts columns as df
df.iloc[index] >> Extracts the Row by idx
df.iloc[i:i] >> Extracts Rows as df
df[df.c1 > n] >> Extracts Row by cond. I
df[df.c1.condition] >> Extracts Row by cond. II
- - - - - - - - - - - - - - - - - - - -
df.reset_index() >> Reset the index
drop = True		 >> Without inserting it
inplace = True		 >> Modify overwriting
df.c1.unique() >> Extracts the set
df.c1.nunique() >> Extracts len(set)
df.c1.mean()		 >> Average of the column
df.c1.median()		 >> Median of the column
df.c1.std()		 >> Standard deviation
df.c1.max() >> Max number
df.c1.min()		 >> Min number
df.c1.count()		 >> len of the set
df.groupby(c1).c2.mean()* >> Groups c1
df.groupby(c1).id.count()* >> Counter
df.groupby(c1).c2.apply(lb)* >> lambda
df.groupby([c1,c2]).c3* >> Multiple g
* > .reset_index() >> To reset df
- - - - - - - - - - - - - - - - - - - -
df.pivot(columns = c2, index = c1, values = v)
pd.merge(df1, df2*)		 >> Merge method I
df1.merge(df2)			 >> Merge method II
df1.merge(df2).merge(df3)
* > how = ‘outer’  ‘inner’  ‘right’  ‘left’
- - - - - - - - - - - - - - - - - - - -
pd.merge(df1, df2, left_on = c1, right_on = c3)*
>> To merge 2 data frame with same column
* > suffixes = [name1, name2]
- - - - - - - - - - - - - - - - - - - -
pd.concat([df1, df2])
df[columns] = list >> Adding a column
- - - - - - - - - - - - - - - - - - - -
RENAMING COLUMNS:
df.columns = list >> Modifying names
df.rename(columns = {old:new}, inplace=True)
df.sort_values(by = [‘c1‘, ‘c2‘], ascending = False)
df[col] = df.c1.apply() >> Modify column
df[col] = df.c1-apply(lb) >> lb = lambda
- - - - - - - - - - - - - - - - - - - -
lb = lambda row: row.c1 >> Lambda in rows
df[col] = df.apply(lb, axis = 1)
mtx = np.array(lst1, lst2, lst3)
np.mean(mtx) >>Total data mean
np.mean(mtx, axis = 0) >> Columns mean
np.mean(mtx, axis = 1) >> Rows mean

More Related Content

Similar to Cheatsheet_Python.pdf

pandas dataframe notes.pdf
pandas dataframe notes.pdfpandas dataframe notes.pdf
pandas dataframe notes.pdfAjeshSurejan2
 
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docx
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docxlab03build.bat@echo offclsset DRIVE_LETTER=1set.docx
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docxDIPESH30
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7decoupled
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with PythonHan Lee
 
The Ring programming language version 1.2 book - Part 24 of 84
The Ring programming language version 1.2 book - Part 24 of 84The Ring programming language version 1.2 book - Part 24 of 84
The Ring programming language version 1.2 book - Part 24 of 84Mahmoud Samir Fayed
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingMuthu Vinayagam
 
Lists.pptx
Lists.pptxLists.pptx
Lists.pptxYagna15
 
Артём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data AnalysisАртём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data AnalysisSpbDotNet Community
 
MySQL 5.7 NF – JSON Datatype 활용
MySQL 5.7 NF – JSON Datatype 활용MySQL 5.7 NF – JSON Datatype 활용
MySQL 5.7 NF – JSON Datatype 활용I Goo Lee
 
The Ring programming language version 1.3 book - Part 25 of 88
The Ring programming language version 1.3 book - Part 25 of 88The Ring programming language version 1.3 book - Part 25 of 88
The Ring programming language version 1.3 book - Part 25 of 88Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.5.4 book - Part 23 of 185The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.5.4 book - Part 23 of 185Mahmoud Samir Fayed
 

Similar to Cheatsheet_Python.pdf (20)

Mysql
MysqlMysql
Mysql
 
Mysql
MysqlMysql
Mysql
 
Mysql
MysqlMysql
Mysql
 
pandas dataframe notes.pdf
pandas dataframe notes.pdfpandas dataframe notes.pdf
pandas dataframe notes.pdf
 
Stacks.ppt
Stacks.pptStacks.ppt
Stacks.ppt
 
Stacks.ppt
Stacks.pptStacks.ppt
Stacks.ppt
 
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docx
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docxlab03build.bat@echo offclsset DRIVE_LETTER=1set.docx
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docx
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
 
The Ring programming language version 1.2 book - Part 24 of 84
The Ring programming language version 1.2 book - Part 24 of 84The Ring programming language version 1.2 book - Part 24 of 84
The Ring programming language version 1.2 book - Part 24 of 84
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python Programming
 
Data import-cheatsheet
Data import-cheatsheetData import-cheatsheet
Data import-cheatsheet
 
Lists.pptx
Lists.pptxLists.pptx
Lists.pptx
 
Артём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data AnalysisАртём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data Analysis
 
tidyr.pdf
tidyr.pdftidyr.pdf
tidyr.pdf
 
MySQL 5.7 NF – JSON Datatype 활용
MySQL 5.7 NF – JSON Datatype 활용MySQL 5.7 NF – JSON Datatype 활용
MySQL 5.7 NF – JSON Datatype 활용
 
The Ring programming language version 1.3 book - Part 25 of 88
The Ring programming language version 1.3 book - Part 25 of 88The Ring programming language version 1.3 book - Part 25 of 88
The Ring programming language version 1.3 book - Part 25 of 88
 
The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.5.4 book - Part 23 of 185The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.5.4 book - Part 23 of 185
 
R programming
R programmingR programming
R programming
 

Recently uploaded

Internshala Student Partner 6.0 Jadavpur University Certificate
Internshala Student Partner 6.0 Jadavpur University CertificateInternshala Student Partner 6.0 Jadavpur University Certificate
Internshala Student Partner 6.0 Jadavpur University CertificateSoham Mondal
 
VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service Cuttack
VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service CuttackVIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service Cuttack
VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service CuttackSuhani Kapoor
 
Call Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts Service
Call Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts ServiceCall Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts Service
Call Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts Servicejennyeacort
 
VIP Call Girl Bhilai Aashi 8250192130 Independent Escort Service Bhilai
VIP Call Girl Bhilai Aashi 8250192130 Independent Escort Service BhilaiVIP Call Girl Bhilai Aashi 8250192130 Independent Escort Service Bhilai
VIP Call Girl Bhilai Aashi 8250192130 Independent Escort Service BhilaiSuhani Kapoor
 
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一2s3dgmej
 
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girls
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call GirlsDelhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girls
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girlsshivangimorya083
 
do's and don'ts in Telephone Interview of Job
do's and don'ts in Telephone Interview of Jobdo's and don'ts in Telephone Interview of Job
do's and don'ts in Telephone Interview of JobRemote DBA Services
 
Experience Certificate - Marketing Analyst-Soham Mondal.pdf
Experience Certificate - Marketing Analyst-Soham Mondal.pdfExperience Certificate - Marketing Analyst-Soham Mondal.pdf
Experience Certificate - Marketing Analyst-Soham Mondal.pdfSoham Mondal
 
VIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service Cuttack
VIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service CuttackVIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service Cuttack
VIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service CuttackSuhani Kapoor
 
Preventing and ending sexual harassment in the workplace.pptx
Preventing and ending sexual harassment in the workplace.pptxPreventing and ending sexual harassment in the workplace.pptx
Preventing and ending sexual harassment in the workplace.pptxGry Tina Tinde
 
VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...
VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...
VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...Suhani Kapoor
 
办理学位证(纽伦堡大学文凭证书)纽伦堡大学毕业证成绩单原版一模一样
办理学位证(纽伦堡大学文凭证书)纽伦堡大学毕业证成绩单原版一模一样办理学位证(纽伦堡大学文凭证书)纽伦堡大学毕业证成绩单原版一模一样
办理学位证(纽伦堡大学文凭证书)纽伦堡大学毕业证成绩单原版一模一样umasea
 
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...Suhani Kapoor
 
Ioannis Tzachristas Self-Presentation for MBA.pdf
Ioannis Tzachristas Self-Presentation for MBA.pdfIoannis Tzachristas Self-Presentation for MBA.pdf
Ioannis Tzachristas Self-Presentation for MBA.pdfjtzach
 
定制(UOIT学位证)加拿大安大略理工大学毕业证成绩单原版一比一
 定制(UOIT学位证)加拿大安大略理工大学毕业证成绩单原版一比一 定制(UOIT学位证)加拿大安大略理工大学毕业证成绩单原版一比一
定制(UOIT学位证)加拿大安大略理工大学毕业证成绩单原版一比一Fs sss
 
加利福尼亚艺术学院毕业证文凭证书( 咨询 )证书双学位
加利福尼亚艺术学院毕业证文凭证书( 咨询 )证书双学位加利福尼亚艺术学院毕业证文凭证书( 咨询 )证书双学位
加利福尼亚艺术学院毕业证文凭证书( 咨询 )证书双学位obuhobo
 
女王大学硕士毕业证成绩单(加急办理)认证海外毕业证
女王大学硕士毕业证成绩单(加急办理)认证海外毕业证女王大学硕士毕业证成绩单(加急办理)认证海外毕业证
女王大学硕士毕业证成绩单(加急办理)认证海外毕业证obuhobo
 
内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士
内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士
内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士obuhobo
 
CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service 🧳
CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service  🧳CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service  🧳
CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service 🧳anilsa9823
 

Recently uploaded (20)

Internshala Student Partner 6.0 Jadavpur University Certificate
Internshala Student Partner 6.0 Jadavpur University CertificateInternshala Student Partner 6.0 Jadavpur University Certificate
Internshala Student Partner 6.0 Jadavpur University Certificate
 
VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service Cuttack
VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service CuttackVIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service Cuttack
VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service Cuttack
 
Call Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts Service
Call Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts ServiceCall Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts Service
Call Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts Service
 
VIP Call Girl Bhilai Aashi 8250192130 Independent Escort Service Bhilai
VIP Call Girl Bhilai Aashi 8250192130 Independent Escort Service BhilaiVIP Call Girl Bhilai Aashi 8250192130 Independent Escort Service Bhilai
VIP Call Girl Bhilai Aashi 8250192130 Independent Escort Service Bhilai
 
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一
 
Call Girls In Prashant Vihar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
Call Girls In Prashant Vihar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCeCall Girls In Prashant Vihar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
Call Girls In Prashant Vihar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
 
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girls
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call GirlsDelhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girls
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girls
 
do's and don'ts in Telephone Interview of Job
do's and don'ts in Telephone Interview of Jobdo's and don'ts in Telephone Interview of Job
do's and don'ts in Telephone Interview of Job
 
Experience Certificate - Marketing Analyst-Soham Mondal.pdf
Experience Certificate - Marketing Analyst-Soham Mondal.pdfExperience Certificate - Marketing Analyst-Soham Mondal.pdf
Experience Certificate - Marketing Analyst-Soham Mondal.pdf
 
VIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service Cuttack
VIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service CuttackVIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service Cuttack
VIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service Cuttack
 
Preventing and ending sexual harassment in the workplace.pptx
Preventing and ending sexual harassment in the workplace.pptxPreventing and ending sexual harassment in the workplace.pptx
Preventing and ending sexual harassment in the workplace.pptx
 
VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...
VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...
VIP Call Girls Service Jamshedpur Aishwarya 8250192130 Independent Escort Ser...
 
办理学位证(纽伦堡大学文凭证书)纽伦堡大学毕业证成绩单原版一模一样
办理学位证(纽伦堡大学文凭证书)纽伦堡大学毕业证成绩单原版一模一样办理学位证(纽伦堡大学文凭证书)纽伦堡大学毕业证成绩单原版一模一样
办理学位证(纽伦堡大学文凭证书)纽伦堡大学毕业证成绩单原版一模一样
 
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
 
Ioannis Tzachristas Self-Presentation for MBA.pdf
Ioannis Tzachristas Self-Presentation for MBA.pdfIoannis Tzachristas Self-Presentation for MBA.pdf
Ioannis Tzachristas Self-Presentation for MBA.pdf
 
定制(UOIT学位证)加拿大安大略理工大学毕业证成绩单原版一比一
 定制(UOIT学位证)加拿大安大略理工大学毕业证成绩单原版一比一 定制(UOIT学位证)加拿大安大略理工大学毕业证成绩单原版一比一
定制(UOIT学位证)加拿大安大略理工大学毕业证成绩单原版一比一
 
加利福尼亚艺术学院毕业证文凭证书( 咨询 )证书双学位
加利福尼亚艺术学院毕业证文凭证书( 咨询 )证书双学位加利福尼亚艺术学院毕业证文凭证书( 咨询 )证书双学位
加利福尼亚艺术学院毕业证文凭证书( 咨询 )证书双学位
 
女王大学硕士毕业证成绩单(加急办理)认证海外毕业证
女王大学硕士毕业证成绩单(加急办理)认证海外毕业证女王大学硕士毕业证成绩单(加急办理)认证海外毕业证
女王大学硕士毕业证成绩单(加急办理)认证海外毕业证
 
内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士
内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士
内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士
 
CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service 🧳
CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service  🧳CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service  🧳
CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service 🧳
 

Cheatsheet_Python.pdf

  • 1. PYTHON 3 CHEET SHEET BY @CHARLSTOWN CREATOR: GUIDO VAN ROSSUM YEAR: 1991 LATEST VERSION (2019): 3.7.4 TOP LIBRARIES: TENSORFLOW, SCIKIT-LEARN, NUMPY, KERAS, PYTORCH, PANDAS, SCIPY STRING OPERATORS “Hello world” ELEMENTAL LIBRARIES import * INT/FLOAT OPERATORS 3 + 2.56 LIST OPERATORS [“A”, “B”, 5, True] DICT. OPERATORS {ky1: “A”, ky2: list} TIMING THE CODE LOOPS FUNCTION & LAMBDA: LIST & DICT COMPREHENSIONS str(29) > Int/Float to string len(“string”) > Total string length “My” + “age is:” + “28” > Sum strings “Hey!” * 3 > Repeat string by 3 “a“ in “chartlstown“ > True if str in str ‘letters‘.isalpha() > Check only letters ‘string’.upper() > STR to CAPS-CASE ‘string‘.lower() > STR to lower-case ‘string‘.title() > First letter to CAPS list(“string“) > Letters to list ‘my string‘.split() > Words to List ““.join(list) > List to String by ““ “AB“.replace(“A”, “B”) > Replace AB > BB string.find(“A”) > Index from match “ A “.strip() > No leading spaces f”My age: {28}” > Insert in string “”My age: {}”.format(28) > Old insert in string “AB”CD” > Include symbol “ “n” > New line in string “t” > Tabulator in string var = input(‘question?’) >Input string form import lib > Import all from lib from lib import function > Import function I lib.function() > Import function II dir(math) > Show all functions import library as lb >Library shortcut int(“25“) > String to integer type() > Returns type A//B > Returns ratio A&B > Returns reminder divmod(A, B) > Ratio/reminder len() > Returns lenght max() > Max. value min() > Min. value abs() > Absolute value pow(5, 2) > 5 powered by 2 5**2 > 5 powered by 2 round(A, 3) > Round 3 decimals sum(list) > Sum all list items len(list) > Count items in list list(range(0,10,2)) > List from range list.reverse() > Reverse the list lst[idx] > Element index lst[idx] = “item” > Change item lst.append(‘item’) > Add item lst[-5:] > Slicing list list.index(“B”) > Position index list.insert(0, A) > Insert item by index list.remove(5) > Remove element list.count(A) > A frequency list.sort() > Sort in same list sorted(lst) > Sort in new list lst.pop() > Last item list(zip(lst_1, lst_2)) > Entwine pair of lists enumerate(list) > Add index to list dic[key] = val > Add a key dic.update({ky: v, ky: v}) > Add multiple keys dic[key] = val > Overwrites value dic[key] > Extracts a value I dic.get(key) > Extracts a value II dic.get(key, DefVal) > Extracts a value III dic.pop(key) > Delete K and V I del dic[k] > Delete K and V II dic.keys() > Keys List dic.values() > Values list dic.items() > Returns K and V key in dict > Checks key dict(zip(lst_1, lst_2)) > Pair lists to Dict. time.time() > Get elapsed time time.sleep(s) > Pause code s secs. time.localtime() > Get local time for item in list: > for loop print(item) > Iterate by items while limit <= 5: > while loop limit += 1 > Iterate by condition def switch(in1, in 2): > Code as function return (in2, in1) > Switch variables switch(“a”, “b”) > Run function on a,b plus_one = lambda x: x+1> Code as expression plus_one(5) > Number plus 1 LIST COMPREHENSION lst_A = [i for i in lst_B if i < 0] LIST COMPREHENSION NESTED lst_A = [i if i < 0 else i-5 for i in lst_B] LIST COMPREHENSION NESTED lst_A = [[i+1 for i in x] for x in lst_B] DICT COMPREHENSION {key: value for key, value in dict.items()}
  • 2. BASIC FUNCTIONS import numpy as np DATA FRAMES import pandas as pd EXTRACTING COLUMNS AND ROWS PANDAS AGGREGATES (COMANDS) P.A. (GROOPING) MERGE METHODS ADD AND RENAME COLUMNS SORTING METHODS APPLY MODIFICATIONS & LAMBDA MATRIX import numpy as np NUMPY_LIBRARY PANDAS_LIBRARY IMPORTING CSV FILES: np.getfromtxt(‘f.csv’, delimiter = ‘,’) - - - - - - - - - - - - - - - - - - - - np.mean(lst) >> Average np.sort(lst) >> Sort the list np.median(lst) >> Median np.percentile(lst, n) >> Percentil n% np.std(lst) >> Standard devi. np.mean(mtx < n) >> Conditions np.var() >> Variance IMPORTING CSV FILES: pd.read_csv(‘f.csv’) - - - - - - - - - - - - - - - - - - - - pd.DataFrame(Dict) >> Create a DF I columns = [list] >> Create a DF II - - - - - - - - - - - - - - - - - - - - df.head(n) >> shows first n rows df.info() >> entries and data df.column.values >> Extract column df[‘colum’] >> Extract multiple clmns df[[c1, c2]] >> Extracts columns as df df.iloc[index] >> Extracts the Row by idx df.iloc[i:i] >> Extracts Rows as df df[df.c1 > n] >> Extracts Row by cond. I df[df.c1.condition] >> Extracts Row by cond. II - - - - - - - - - - - - - - - - - - - - df.reset_index() >> Reset the index drop = True >> Without inserting it inplace = True >> Modify overwriting df.c1.unique() >> Extracts the set df.c1.nunique() >> Extracts len(set) df.c1.mean() >> Average of the column df.c1.median() >> Median of the column df.c1.std() >> Standard deviation df.c1.max() >> Max number df.c1.min() >> Min number df.c1.count() >> len of the set df.groupby(c1).c2.mean()* >> Groups c1 df.groupby(c1).id.count()* >> Counter df.groupby(c1).c2.apply(lb)* >> lambda df.groupby([c1,c2]).c3* >> Multiple g * > .reset_index() >> To reset df - - - - - - - - - - - - - - - - - - - - df.pivot(columns = c2, index = c1, values = v) pd.merge(df1, df2*) >> Merge method I df1.merge(df2) >> Merge method II df1.merge(df2).merge(df3) * > how = ‘outer’ ‘inner’ ‘right’ ‘left’ - - - - - - - - - - - - - - - - - - - - pd.merge(df1, df2, left_on = c1, right_on = c3)* >> To merge 2 data frame with same column * > suffixes = [name1, name2] - - - - - - - - - - - - - - - - - - - - pd.concat([df1, df2]) df[columns] = list >> Adding a column - - - - - - - - - - - - - - - - - - - - RENAMING COLUMNS: df.columns = list >> Modifying names df.rename(columns = {old:new}, inplace=True) df.sort_values(by = [‘c1‘, ‘c2‘], ascending = False) df[col] = df.c1.apply() >> Modify column df[col] = df.c1-apply(lb) >> lb = lambda - - - - - - - - - - - - - - - - - - - - lb = lambda row: row.c1 >> Lambda in rows df[col] = df.apply(lb, axis = 1) mtx = np.array(lst1, lst2, lst3) np.mean(mtx) >>Total data mean np.mean(mtx, axis = 0) >> Columns mean np.mean(mtx, axis = 1) >> Rows mean