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 whitespace from ends
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 Pandas for Data Science cheatsheet
Dr. Volkan OBAN
 
PDF
Python matplotlib cheat_sheet
Nishant Upadhyay
 
PPTX
Python-List.pptx
AnitaDevi158873
 
PPTX
6-Python-Recursion PPT.pptx
Venkateswara Babu Ravipati
 
PDF
Pandas Cheat Sheet
ACASH1011
 
PDF
Python Programming: Lists, Modules, Exceptions
Sreedhar Chowdam
 
PDF
Chapter Functions for grade 12 computer Science
KrithikaTM
 
PDF
Vector
Joyjit Choudhury
 
Python Pandas for Data Science cheatsheet
Dr. Volkan OBAN
 
Python matplotlib cheat_sheet
Nishant Upadhyay
 
Python-List.pptx
AnitaDevi158873
 
6-Python-Recursion PPT.pptx
Venkateswara Babu Ravipati
 
Pandas Cheat Sheet
ACASH1011
 
Python Programming: Lists, Modules, Exceptions
Sreedhar Chowdam
 
Chapter Functions for grade 12 computer Science
KrithikaTM
 

What's hot (20)

PPTX
Functions & Recursion
Nishant Munjal
 
PDF
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
 
PPT
Lecture 1 data structures and algorithms
Aakash deep Singhal
 
PPTX
Arrays, Structures And Enums
Bhushan Mulmule
 
PPTX
Hashing in datastructure
rajshreemuthiah
 
PDF
Python File Handling | File Operations in Python | Learn python programming |...
Edureka!
 
PDF
Python avancé : Ensemble, dictionnaire et base de données
ECAM Brussels Engineering School
 
PPTX
Evaluation of postfix expression using stack
shubhajitCHATTERJEE2
 
PPTX
Linked List - Insertion & Deletion
Afaq Mansoor Khan
 
PDF
Python avancé : Tuple et objet
ECAM Brussels Engineering School
 
PPT
Expression evaluation
JeeSa Sultana
 
PPTX
Database connectivity in python
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Cours algo: Les pointeurs
Sana REFAI
 
PDF
Python_ 3 CheatSheet
Dr. Volkan OBAN
 
PDF
Python libraries
Prof. Dr. K. Adisesha
 
PDF
Numpy python cheat_sheet
Nishant Upadhyay
 
PPTX
Stack using Linked List
Sayantan Sur
 
PPTX
Python array
Arnab Chakraborty
 
PDF
Python avancé : Lecture et écriture de fichiers
ECAM Brussels Engineering School
 
PPTX
Data Structures in Python
Devashish Kumar
 
Functions & Recursion
Nishant Munjal
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
 
Lecture 1 data structures and algorithms
Aakash deep Singhal
 
Arrays, Structures And Enums
Bhushan Mulmule
 
Hashing in datastructure
rajshreemuthiah
 
Python File Handling | File Operations in Python | Learn python programming |...
Edureka!
 
Python avancé : Ensemble, dictionnaire et base de données
ECAM Brussels Engineering School
 
Evaluation of postfix expression using stack
shubhajitCHATTERJEE2
 
Linked List - Insertion & Deletion
Afaq Mansoor Khan
 
Python avancé : Tuple et objet
ECAM Brussels Engineering School
 
Expression evaluation
JeeSa Sultana
 
Database connectivity in python
baabtra.com - No. 1 supplier of quality freshers
 
Cours algo: Les pointeurs
Sana REFAI
 
Python_ 3 CheatSheet
Dr. Volkan OBAN
 
Python libraries
Prof. Dr. K. Adisesha
 
Numpy python cheat_sheet
Nishant Upadhyay
 
Stack using Linked List
Sayantan Sur
 
Python array
Arnab Chakraborty
 
Python avancé : Lecture et écriture de fichiers
ECAM Brussels Engineering School
 
Data Structures in Python
Devashish Kumar
 
Ad

Similar to Python For Data Science Cheat Sheet (20)

PDF
Python.pdf
TanTran598844
 
PDF
python-cheatsheets that will be for coders
sarafbisesh
 
PDF
python-cheatsheets.pdf
Kalyan969491
 
PDF
DataCamp Cheat Sheets 4 Python Users (2020)
EMRE AKCAOGLU
 
PPTX
Chapter 5-Numpy-Pandas.pptx python programming
ssuser77162c
 
PDF
Arrays in python
Lifna C.S
 
PDF
Numpy - Array.pdf
AnkitaArjunDevkate
 
PDF
Python_cheatsheet_numpy.pdf
AnonymousUser67
 
PDF
Numpy python cheat_sheet
Zahid Hasan
 
PPTX
Numpy_Pandas_for beginners_________.pptx
Abhi Marvel
 
PPTX
Lecture 2 _Foundions foundions NumPyI.pptx
disserdekabrcha
 
PPTX
numpydocococ34554367827839271966666.pptx
sankarhariharan2007
 
PDF
ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...
DineshThallapelly
 
PDF
numpy.pdf
DrSudheerHanumanthak
 
PPTX
numpy code and examples with attributes.pptx
swathis752031
 
PDF
Numpy cheat-sheet
Arief Kurniawan
 
PPTX
Usage of Python NumPy, 1Dim, 2Dim Arrays
NarendraDev11
 
PPTX
PPT data science python sequence numpy.pptx
AkashAgrawal434750
 
PDF
Introduction to NumPy (PyData SV 2013)
PyData
 
PDF
Introduction to NumPy
Huy Nguyen
 
Python.pdf
TanTran598844
 
python-cheatsheets that will be for coders
sarafbisesh
 
python-cheatsheets.pdf
Kalyan969491
 
DataCamp Cheat Sheets 4 Python Users (2020)
EMRE AKCAOGLU
 
Chapter 5-Numpy-Pandas.pptx python programming
ssuser77162c
 
Arrays in python
Lifna C.S
 
Numpy - Array.pdf
AnkitaArjunDevkate
 
Python_cheatsheet_numpy.pdf
AnonymousUser67
 
Numpy python cheat_sheet
Zahid Hasan
 
Numpy_Pandas_for beginners_________.pptx
Abhi Marvel
 
Lecture 2 _Foundions foundions NumPyI.pptx
disserdekabrcha
 
numpydocococ34554367827839271966666.pptx
sankarhariharan2007
 
ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...
DineshThallapelly
 
numpy code and examples with attributes.pptx
swathis752031
 
Numpy cheat-sheet
Arief Kurniawan
 
Usage of Python NumPy, 1Dim, 2Dim Arrays
NarendraDev11
 
PPT data science python sequence numpy.pptx
AkashAgrawal434750
 
Introduction to NumPy (PyData SV 2013)
PyData
 
Introduction to NumPy
Huy Nguyen
 
Ad

Recently uploaded (20)

PDF
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
PDF
Software Development Company | KodekX
KodekX
 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PDF
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PPT
L2 Rules of Netiquette in Empowerment technology
Archibal2
 
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
Software Development Company | KodekX
KodekX
 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
L2 Rules of Netiquette in Empowerment technology
Archibal2
 

Python For Data Science Cheat Sheet

  • 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 whitespace from ends 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