SlideShare a Scribd company logo
Selecting List Elements
Import libraries
>>> import numpy
>>> import numpy as np
Selective import
>>> from math import pi
>>> help(str)
PythonForDataScience Cheat Sheet
Python Basics
Learn More Python for Data Science Interactively at www.datacamp.com
Variable Assignment
Strings
>>> x=5
>>> x
5
>>> x+2 Sum of two variables
7
>>> x-2 Subtraction of two variables
3
>>> x*2 Multiplication of two variables
10
>>> x**2 Exponentiation of a variable
25
>>> x%2 Remainder of a variable
1
>>> x/float(2) Division of a variable
2.5
Variables and Data Types
str() '5', '3.45', 'True'
int() 5, 3, 1
float() 5.0, 1.0
bool() True, True, True
Variables to strings
Variables to integers
Variables to floats
Variables to booleans
Lists
>>> a = 'is'
>>> b = 'nice'
>>> my_list = ['my', 'list', a, b]
>>> my_list2 = [[4,5,6,7], [3,4,5,6]]
Subset
>>> my_list[1]
>>> my_list[-3]
Slice
>>> my_list[1:3]
>>> my_list[1:]
>>> my_list[:3]
>>> my_list[:]
Subset Lists of Lists
>>> my_list2[1][0]
>>> my_list2[1][:2]
Also see NumPy Arrays
>>> my_list.index(a)
>>> my_list.count(a)
>>> my_list.append('!')
>>> my_list.remove('!')
>>> del(my_list[0:1])
>>> my_list.reverse()
>>> my_list.extend('!')
>>> my_list.pop(-1)
>>> my_list.insert(0,'!')
>>> my_list.sort()
Get the index of an item
Count an item
Append an item at a time
Remove an item
Remove an item
Reverse the list
Append an item
Remove an item
Insert an item
Sort the list
Index starts at 0
Select item at index 1
Select 3rd last item
Select items at index 1 and 2
Select items after index 0
Select items before index 3
Copy my_list
my_list[list][itemOfList]
Libraries
>>> my_string.upper()
>>> my_string.lower()
>>> my_string.count('w')
>>> my_string.replace('e', 'i')
>>> my_string.strip()
>>> my_string = 'thisStringIsAwesome'
>>> my_string
'thisStringIsAwesome'
Numpy Arrays
>>> my_list = [1, 2, 3, 4]
>>> my_array = np.array(my_list)
>>> my_2darray = np.array([[1,2,3],[4,5,6]])
>>> my_array.shape
>>> np.append(other_array)
>>> np.insert(my_array, 1, 5)
>>> np.delete(my_array,[1])
>>> np.mean(my_array)
>>> np.median(my_array)
>>> my_array.corrcoef()
>>> np.std(my_array)
Asking For Help
>>> my_string[3]
>>> my_string[4:9]
Subset
>>> my_array[1]
2
Slice
>>> my_array[0:2]
array([1, 2])
Subset 2D Numpy arrays
>>> my_2darray[:,0]
array([1, 4])
>>> my_list + my_list
['my', 'list', 'is', 'nice', 'my', 'list', 'is', 'nice']
>>> my_list * 2
['my', 'list', 'is', 'nice', 'my', 'list', 'is', 'nice']
>>> my_list2 > 4
True
>>> my_array > 3
array([False, False, False, True], dtype=bool)
>>> my_array * 2
array([2, 4, 6, 8])
>>> my_array + np.array([5, 6, 7, 8])
array([6, 8, 10, 12])
>>> my_string * 2
'thisStringIsAwesomethisStringIsAwesome'
>>> my_string + 'Innit'
'thisStringIsAwesomeInnit'
>>> 'm' in my_string
True DataCamp
Learn Python for Data Science Interactively
Scientific computing
Data analysis
2D plotting
Machine learning
Also see Lists
Get the dimensions of the array
Append items to an array
Insert items in an array
Delete items in an array
Mean of the array
Median of the array
Correlation coefficient
Standard deviation
String to uppercase
String to lowercase
Count String elements
Replace String elements
Strip whitespaces
Select item at index 1
Select items at index 0 and 1
my_2darray[rows, columns]
Install Python
Calculations With Variables
Leading open data science platform
powered by Python
Free IDE that is included
with Anaconda
Create and share
documents with live code,
visualizations, text, ...
Types and Type Conversion
String Operations
List Operations
List Methods
Index starts at 0
String Methods
String Operations
Selecting Numpy Array Elements Index starts at 0
Numpy Array Operations
Numpy Array Functions

More Related Content

PDF
Python For Data Science Cheat Sheet
Karlijn Willems
 
PDF
Python matplotlib cheat_sheet
Nishant Upadhyay
 
PDF
Python3 cheatsheet
Gil Cohen
 
PDF
Cheat Sheet for Machine Learning in Python: Scikit-learn
Karlijn Willems
 
PDF
Pandas pythonfordatascience
Nishant Upadhyay
 
PDF
Cheat sheet python3
sxw2k
 
PDF
Python seaborn cheat_sheet
Nishant Upadhyay
 
PDF
Python_ 3 CheatSheet
Dr. Volkan OBAN
 
Python For Data Science Cheat Sheet
Karlijn Willems
 
Python matplotlib cheat_sheet
Nishant Upadhyay
 
Python3 cheatsheet
Gil Cohen
 
Cheat Sheet for Machine Learning in Python: Scikit-learn
Karlijn Willems
 
Pandas pythonfordatascience
Nishant Upadhyay
 
Cheat sheet python3
sxw2k
 
Python seaborn cheat_sheet
Nishant Upadhyay
 
Python_ 3 CheatSheet
Dr. Volkan OBAN
 

What's hot (20)

PDF
Python Workshop Part 2. LUG Maniapl
Ankur Shrivastava
 
PDF
Python bokeh cheat_sheet
Nishant Upadhyay
 
PPTX
Python programming -Tuple and Set Data type
Megha V
 
PDF
Arrays in python
Lifna C.S
 
PDF
Python 2.5 reference card (2009)
gekiaruj
 
PDF
The Chain Rule, Part 2
Pablo Antuna
 
PDF
Python Variable Types, List, Tuple, Dictionary
Soba Arjun
 
PDF
Arrays In Python | Python Array Operations | Edureka
Edureka!
 
PDF
Basic data structures in python
Lifna C.S
 
PPTX
List in Python
Siddique Ibrahim
 
PDF
Python programming : List and tuples
Emertxe Information Technologies Pvt Ltd
 
PPTX
Python PCEP Tuples and Dictionaries
IHTMINSTITUTE
 
PDF
List , tuples, dictionaries and regular expressions in python
channa basava
 
PDF
iRODS Rule Language Cheat Sheet
Samuel Lampa
 
PPTX
Java arrays
Maneesha Caldera
 
PDF
The Ring programming language version 1.7 book - Part 26 of 196
Mahmoud Samir Fayed
 
PPT
Oop lecture7
Shahriar Robbani
 
PPTX
Basic data structures in python
Celine George
 
PDF
Merge sort: illustrated step-by-step walk through
Yoshi Watanabe
 
Python Workshop Part 2. LUG Maniapl
Ankur Shrivastava
 
Python bokeh cheat_sheet
Nishant Upadhyay
 
Python programming -Tuple and Set Data type
Megha V
 
Arrays in python
Lifna C.S
 
Python 2.5 reference card (2009)
gekiaruj
 
The Chain Rule, Part 2
Pablo Antuna
 
Python Variable Types, List, Tuple, Dictionary
Soba Arjun
 
Arrays In Python | Python Array Operations | Edureka
Edureka!
 
Basic data structures in python
Lifna C.S
 
List in Python
Siddique Ibrahim
 
Python programming : List and tuples
Emertxe Information Technologies Pvt Ltd
 
Python PCEP Tuples and Dictionaries
IHTMINSTITUTE
 
List , tuples, dictionaries and regular expressions in python
channa basava
 
iRODS Rule Language Cheat Sheet
Samuel Lampa
 
Java arrays
Maneesha Caldera
 
The Ring programming language version 1.7 book - Part 26 of 196
Mahmoud Samir Fayed
 
Oop lecture7
Shahriar Robbani
 
Basic data structures in python
Celine George
 
Merge sort: illustrated step-by-step walk through
Yoshi Watanabe
 
Ad

Similar to 1 pythonbasic (20)

PDF
Numpy python cheat_sheet
Zahid Hasan
 
PDF
Python_cheatsheet_numpy.pdf
AnonymousUser67
 
PDF
Numpy python cheat_sheet
Nishant Upadhyay
 
PDF
python-cheatsheets that will be for coders
sarafbisesh
 
PDF
python-cheatsheets.pdf
Kalyan969491
 
PDF
Python.pdf
TanTran598844
 
PDF
Numpy_Cheat_Sheet.pdf
SkyNerve
 
PPT
UNIT III_Python Programming_aditya COllege
Ramanamurthy Banda
 
PPT
UNIT III_Python Programming_aditya COllege
Ramanamurthy Banda
 
PDF
DataCamp Cheat Sheets 4 Python Users (2020)
EMRE AKCAOGLU
 
PPTX
NUMPY LIBRARY study materials PPT 2.pptx
CHETHANKUMAR274045
 
PPTX
Pythonlearn-08-Lists.pptx
MihirDatir
 
ODP
Intro
Cosmin Poieana
 
PDF
جلسه سوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
Mohammad Reza Kamalifard
 
PPTX
Python list tuple dictionary .pptx
miteshchaudhari4466
 
PPTX
Pythonlearn-08-Lists.pptx
MihirDatir1
 
PDF
Py4Inf-08-Lists ListsListsListsListsListsListsListsListsListsListsListsLists.pdf
horiamommand
 
PDF
Python elements list you can study .pdf
AUNGHTET61
 
PPTX
Datastructures in python
hydpy
 
PPTX
‏‏chap6 list tuples.pptx
RamiHarrathi1
 
Numpy python cheat_sheet
Zahid Hasan
 
Python_cheatsheet_numpy.pdf
AnonymousUser67
 
Numpy python cheat_sheet
Nishant Upadhyay
 
python-cheatsheets that will be for coders
sarafbisesh
 
python-cheatsheets.pdf
Kalyan969491
 
Python.pdf
TanTran598844
 
Numpy_Cheat_Sheet.pdf
SkyNerve
 
UNIT III_Python Programming_aditya COllege
Ramanamurthy Banda
 
UNIT III_Python Programming_aditya COllege
Ramanamurthy Banda
 
DataCamp Cheat Sheets 4 Python Users (2020)
EMRE AKCAOGLU
 
NUMPY LIBRARY study materials PPT 2.pptx
CHETHANKUMAR274045
 
Pythonlearn-08-Lists.pptx
MihirDatir
 
جلسه سوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
Mohammad Reza Kamalifard
 
Python list tuple dictionary .pptx
miteshchaudhari4466
 
Pythonlearn-08-Lists.pptx
MihirDatir1
 
Py4Inf-08-Lists ListsListsListsListsListsListsListsListsListsListsListsLists.pdf
horiamommand
 
Python elements list you can study .pdf
AUNGHTET61
 
Datastructures in python
hydpy
 
‏‏chap6 list tuples.pptx
RamiHarrathi1
 
Ad

More from pramod naik (13)

DOCX
Electrical lab
pramod naik
 
DOC
Dsp manual
pramod naik
 
PDF
Adversarial search
pramod naik
 
PDF
3 pandasadvanced
pramod naik
 
PDF
2 pandasbasic
pramod naik
 
PDF
Chapter07
pramod naik
 
PDF
Chapter06
pramod naik
 
PDF
Chapter05
pramod naik
 
PDF
Chapter04b
pramod naik
 
PDF
Chapter04a
pramod naik
 
PDF
Chapter01
pramod naik
 
PDF
Ilsvrc2015 deep residual_learning_kaiminghe
pramod naik
 
PDF
Ganesan dhawanrpt
pramod naik
 
Electrical lab
pramod naik
 
Dsp manual
pramod naik
 
Adversarial search
pramod naik
 
3 pandasadvanced
pramod naik
 
2 pandasbasic
pramod naik
 
Chapter07
pramod naik
 
Chapter06
pramod naik
 
Chapter05
pramod naik
 
Chapter04b
pramod naik
 
Chapter04a
pramod naik
 
Chapter01
pramod naik
 
Ilsvrc2015 deep residual_learning_kaiminghe
pramod naik
 
Ganesan dhawanrpt
pramod naik
 

Recently uploaded (20)

PPTX
Internet Download Manager (IDM) Crack Free Download [Latest 2025] PPTX
awaischaudary317
 
PDF
File system ,data storage,FAT,NTFS,APFS and directory structures
jaydeepprajapati696
 
PDF
LLLLLLLLLLLLLLLLLLLLCABUTAN UNDIAN PELANCARAN ROKET.pdf
ABKARIMBINABDULRAHMA
 
DOCX
This is a security test for Inspectiv test
Firsts Lasts
 
PDF
Trapped Movie trailer (New Media Tools Presentation)
marebecams
 
PDF
GRAPHISOFT ArchiCAD 29.0.0.2001 Crack New Version Latest 2025
itskinga12
 
PDF
Presentación San Patricio Ilustrativo Verde (1).pdf
andressuarezaraya912
 
PDF
DOC-20250716-WA0020..pkjhnb.kjuvhjuhv.kihjdf
sayeedarhan829
 
PPTX
design for presentation purpose can used
vishveshvarvms
 
PDF
Malaria detection through machine learning and deep learning
BhaveshGoyal26
 
PPSX
Eagle in Paintings .ppsx
guimera
 
PDF
Your Love Story, Beautifully Told by FliqaIndia’s Creative Experts
sandeep239227
 
PPTX
2 Human Resource Planning.pptxkkkkkkkkkkkkkkkkkkkk
khushigulati2325
 
DOCX
Nutrition about ICT AND TLE.09111001991981
CharmicahOmayan3
 
PPTX
Q1_Music and Arts_Week 3-4 [Autosaved].pptx
MelissaJeanBayobay1
 
PPTX
Lecture 1b - Diagnostic Analytics Intro and Purpose ver 1.0 (1).pptx
guddipatel10
 
PDF
gri-report-2023.nb hjjhbjhbjbmnmnmbbmbmbm
dsoham206
 
PPTX
Welcome chiku new07.pptxrfgretgregbdffgfdgfd
xoviva2925
 
PDF
iTop VPN Crack New Version Latest 2025?
itskinga12
 
PPTX
ENGLISH 6 WEEK 6 DAY 2.pptxLFLLLLLLLLLLLLLLLLLLLLLLLLLL
DitaSIdnay
 
Internet Download Manager (IDM) Crack Free Download [Latest 2025] PPTX
awaischaudary317
 
File system ,data storage,FAT,NTFS,APFS and directory structures
jaydeepprajapati696
 
LLLLLLLLLLLLLLLLLLLLCABUTAN UNDIAN PELANCARAN ROKET.pdf
ABKARIMBINABDULRAHMA
 
This is a security test for Inspectiv test
Firsts Lasts
 
Trapped Movie trailer (New Media Tools Presentation)
marebecams
 
GRAPHISOFT ArchiCAD 29.0.0.2001 Crack New Version Latest 2025
itskinga12
 
Presentación San Patricio Ilustrativo Verde (1).pdf
andressuarezaraya912
 
DOC-20250716-WA0020..pkjhnb.kjuvhjuhv.kihjdf
sayeedarhan829
 
design for presentation purpose can used
vishveshvarvms
 
Malaria detection through machine learning and deep learning
BhaveshGoyal26
 
Eagle in Paintings .ppsx
guimera
 
Your Love Story, Beautifully Told by FliqaIndia’s Creative Experts
sandeep239227
 
2 Human Resource Planning.pptxkkkkkkkkkkkkkkkkkkkk
khushigulati2325
 
Nutrition about ICT AND TLE.09111001991981
CharmicahOmayan3
 
Q1_Music and Arts_Week 3-4 [Autosaved].pptx
MelissaJeanBayobay1
 
Lecture 1b - Diagnostic Analytics Intro and Purpose ver 1.0 (1).pptx
guddipatel10
 
gri-report-2023.nb hjjhbjhbjbmnmnmbbmbmbm
dsoham206
 
Welcome chiku new07.pptxrfgretgregbdffgfdgfd
xoviva2925
 
iTop VPN Crack New Version Latest 2025?
itskinga12
 
ENGLISH 6 WEEK 6 DAY 2.pptxLFLLLLLLLLLLLLLLLLLLLLLLLLLL
DitaSIdnay
 

1 pythonbasic

  • 1. Selecting List Elements Import libraries >>> import numpy >>> import numpy as np Selective import >>> from math import pi >>> help(str) PythonForDataScience Cheat Sheet Python Basics Learn More Python for Data Science Interactively at www.datacamp.com Variable Assignment Strings >>> x=5 >>> x 5 >>> x+2 Sum of two variables 7 >>> x-2 Subtraction of two variables 3 >>> x*2 Multiplication of two variables 10 >>> x**2 Exponentiation of a variable 25 >>> x%2 Remainder of a variable 1 >>> x/float(2) Division of a variable 2.5 Variables and Data Types str() '5', '3.45', 'True' int() 5, 3, 1 float() 5.0, 1.0 bool() True, True, True Variables to strings Variables to integers Variables to floats Variables to booleans Lists >>> a = 'is' >>> b = 'nice' >>> my_list = ['my', 'list', a, b] >>> my_list2 = [[4,5,6,7], [3,4,5,6]] Subset >>> my_list[1] >>> my_list[-3] Slice >>> my_list[1:3] >>> my_list[1:] >>> my_list[:3] >>> my_list[:] Subset Lists of Lists >>> my_list2[1][0] >>> my_list2[1][:2] Also see NumPy Arrays >>> my_list.index(a) >>> my_list.count(a) >>> my_list.append('!') >>> my_list.remove('!') >>> del(my_list[0:1]) >>> my_list.reverse() >>> my_list.extend('!') >>> my_list.pop(-1) >>> my_list.insert(0,'!') >>> my_list.sort() Get the index of an item Count an item Append an item at a time Remove an item Remove an item Reverse the list Append an item Remove an item Insert an item Sort the list Index starts at 0 Select item at index 1 Select 3rd last item Select items at index 1 and 2 Select items after index 0 Select items before index 3 Copy my_list my_list[list][itemOfList] Libraries >>> my_string.upper() >>> my_string.lower() >>> my_string.count('w') >>> my_string.replace('e', 'i') >>> my_string.strip() >>> my_string = 'thisStringIsAwesome' >>> my_string 'thisStringIsAwesome' Numpy Arrays >>> my_list = [1, 2, 3, 4] >>> my_array = np.array(my_list) >>> my_2darray = np.array([[1,2,3],[4,5,6]]) >>> my_array.shape >>> np.append(other_array) >>> np.insert(my_array, 1, 5) >>> np.delete(my_array,[1]) >>> np.mean(my_array) >>> np.median(my_array) >>> my_array.corrcoef() >>> np.std(my_array) Asking For Help >>> my_string[3] >>> my_string[4:9] Subset >>> my_array[1] 2 Slice >>> my_array[0:2] array([1, 2]) Subset 2D Numpy arrays >>> my_2darray[:,0] array([1, 4]) >>> my_list + my_list ['my', 'list', 'is', 'nice', 'my', 'list', 'is', 'nice'] >>> my_list * 2 ['my', 'list', 'is', 'nice', 'my', 'list', 'is', 'nice'] >>> my_list2 > 4 True >>> my_array > 3 array([False, False, False, True], dtype=bool) >>> my_array * 2 array([2, 4, 6, 8]) >>> my_array + np.array([5, 6, 7, 8]) array([6, 8, 10, 12]) >>> my_string * 2 'thisStringIsAwesomethisStringIsAwesome' >>> my_string + 'Innit' 'thisStringIsAwesomeInnit' >>> 'm' in my_string True DataCamp Learn Python for Data Science Interactively Scientific computing Data analysis 2D plotting Machine learning Also see Lists Get the dimensions of the array Append items to an array Insert items in an array Delete items in an array Mean of the array Median of the array Correlation coefficient Standard deviation String to uppercase String to lowercase Count String elements Replace String elements Strip whitespaces Select item at index 1 Select items at index 0 and 1 my_2darray[rows, columns] Install Python Calculations With Variables Leading open data science platform powered by Python Free IDE that is included with Anaconda Create and share documents with live code, visualizations, text, ... Types and Type Conversion String Operations List Operations List Methods Index starts at 0 String Methods String Operations Selecting Numpy Array Elements Index starts at 0 Numpy Array Operations Numpy Array Functions