Transcription of Python For Data Science Cheat Sheet Lists Also see NumPy ...
1 Selecting List Elements Import libraries>>> import NumPy >>> import NumPy as np Selective import>>> from math import pi>>> help(str) Python For Data Science Cheat SheetPython BasicsLearn More Python for Data Science Interactively at AssignmentStrings>>> 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 and Data Types str() '5', ' ', 'True' int()
2 5, 3, 1 float() , bool() True, True, TrueVariables to stringsVariables to integersVariables to floatsVariables to booleansLists>>> 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>>> (a) >>> (a)>>> ('!')>>> ('!')>>> del(my_list[0:1])>>> ()>>> ('!')>>> (-1)>>> (0,'!)
3 ')>>> ()Get the index of an itemCount an itemAppend an item at a timeRemove an itemRemove an itemReverse the listAppend an itemRemove an itemInsert an itemSort the listIndex starts at 0 Select item at index 1 Select 3rd last itemSelect items at index 1 and 2 Select items after index 0 Select items before index 3 Copy my_listmy_list[list][itemOfList]Librarie s>>> ()>>> ()>>> ('w')>>> ('e', 'i')>>> ()>>> my_string = 'thisStringIsAwesome'>>> my_string'thisStringIsAwesome' NumPy Arrays>>> my_list = [1, 2, 3, 4]>>> my_array = (my_list)>>> my_2darray = ([[1,2,3],[4,5,6]])>>> >>> (other_array)>>> (my_array, 1, 5)>>> (my_array,[1])>>> (my_array)>>> (my_array)>>> ()>>> (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[.]
4 ,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 + ([5, 6, 7, 8]) array([6, 8, 10, 12])>>> my_string * 2 'thisStringIsAwesomethisStringIsAwesome' >>> my_string + 'Innit' 'thisStringIsAwesomeInnit'>>> 'm' in my_string TrueDataCampLearn Python for Data Science InteractivelyScientific computingData analysis2D plottingMachine learningAlso see ListsGet the dimensions of the arrayAppend items to an arrayInsert items in an arrayDelete items in an arrayMean of the arrayMedian of the arrayCorrelation coefficientStandard deviationString to uppercaseString to lowercaseCount String elementsReplace
5 String elementsStrip whitespacesSelect item at index 1 Select items at index 0 and 1my_2darray[rows, columns]Install PythonCalculations With VariablesLeading open data Science platformpowered by PythonFree IDE that is included with AnacondaCreate and share documents with live code, visualizations, text, ..Types and Type ConversionString OperationsList OperationsList MethodsIndex starts at 0 String MethodsString OperationsSelecting NumPy Array ElementsIndex starts at 0 NumPy Array OperationsNumpy Array FunctionsDataCampLearn Python for Data Science InteractivelySaving/Loading NotebooksWorking with Different Programming LanguagesAsking For HelpWidgetsPython For Data Science Cheat SheetJupyter NotebookLearn More Python for Data Science Interactively at provide computation and communication with front-end
6 Interfaces like the notebooks. There are three main kernels: Installing Jupyter Notebook will automatically install the IPython kernel. Create new notebookOpen an existing notebookMake a copy of the current notebookRename notebookWriting Code And TextSave current notebook and record checkpointRevert notebook to a previous checkpointPreview of the printed notebookDownload notebook as - IPython notebook - Python - HTML - Markdown - reST - LaTeX - PDFC lose notebook & stop running any scriptsIRkernelIJuliaCut currently selected cells to clipboardCopy cells from clipboard to current cursor positionPaste cells from clipboard
7 Above current cellPaste cells from clipboard below current cellPaste cells from clipboard on top of current celDelete current cellsRevert Delete Cells invocationSplit up a cell from current cursor positionMerge current cell with the one aboveMerge current cell with the one belowMove current cell upMove current cell downAdjust metadata underlying the current notebookFind and replace in selected cellsInsert image in selected cellsRestart kernelRestart kernel & run all cells Restart kernel & run all cells Interrupt kernelInterrupt kernel & clear all outputConnect back to a remote notebookRun other installed kernelsCode and text are encapsulated by 3 basic cell types: markdown cells, code cells, and raw NBConvert CellsInsert CellsView CellsNotebook widgets provide the ability to visualize and control changes in your data, often as a control like a slider, textbox, etc.
8 You can use them to build interactive GUIs for your notebooks or to synchronize stateful and stateless information between Python and display of Jupyter logo and filenameToggle display of toolbarToggle line numbers in cellsToggle display of cell action icons: - None - Edit metadata - Raw cell format - Slideshow - Attachments - TagsAdd new cell above the current oneAdd new cell below the current oneExecuting CellsRun selected cell(s)Run current cells down and create a new one belowRun current cells down and create a new one aboveRun all cellsSave notebook with interactive widgetsDownload serialized state of all widget models in useEmbed current widgetsWalk through a UI tourList of built-in keyboard shortcutsEdit the built-in keyboard shortcutsNotebook help topicsDescription of markdown available in notebookAbout Jupyter NotebookInformation on unofficial Jupyter Notebook extensionsPython help topicsIPython help topicsNumPy help topics
9 SciPy help topicsPandas help topics SymPy help topicsMatplotlib help topicsRun all cells above the current cellRun all cells below the current cellChange the cell type of current celltoggle, toggle scrolling and clear current outputstoggle, toggle scrolling and clear all output1. Save and checkpoint 2. Insert cell below3. Cut cell4. Copy cell(s)5. Paste cell(s) below6. Move cell up7. Move cell down8. Run current cell 9. Interrupt kernel10. Restart kernel11. Display characteristics12. Open command palette13.
10 Current kernel14. Kernel status15. Log out from notebook serverCommand Mode:Edit Mode:123456789101112131415 Copy attachments of current cellRemove cell attachmentsPaste attachments of current cell 2 Python For Data Science Cheat SheetNumPy BasicsLearn Python for Data Science Interactively at Python for Data Science InteractivelyThe NumPy library is the core library for scientific computing in Python . It provides a high-performance multidimensional array object, and tools for working with these arrays. >>> import NumPy as npUse the following import convention:Creating Arrays>>> ((3,4)) Create an array of zeros>>> ((2,3,4),dtype= ) Create an array of ones>>> d = (10,25,5) Create an array of evenly spaced values (step value) >>> (0,2,9) Create an array of evenly spaced values (number of samples)>>> e = ((2,2),7) Create a constant arra