Transcription

Python For Data Science Cheat SheetPython BasicsLearn More Python for Data Science Interactively at www.datacamp.comLists Also see NumPy Arraysa 'is'b 'nice'my list ['my', 'list', a, b]my list2 [[4,5,6,7], [3,4,5,6]]Selecting List ElementsVariables and Data TypesSubsetVariable Assignment x 5 x5 my list[1] my list[-3]Select item at index 1Select 3rd last item Select items at index 1 and 2Select items after index 0Select items before index 3Copy my listSliceCalculations With Variables x 2Sum of two variables x-2Subtraction of two variables x*2Multiplication of two variables x**2Exponentiation of a variable x%2Remainder of a variable x/float(2)Division of a variable7310251Index starts at 02.5my list[1:3]my list[1:]my list[:3]my list[:]Subset Lists of Lists my list2[1][0] my list2[1][:2]my list[list][itemOfList]str()'5', '3.45', 'True'Variables to stringsint()5, 3, 1Variables to integers 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 4float()5.0, 1.0Variables to floatsbool()True, True, TrueVariables to booleansAsking For Help help(str)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()'thisStringIsAwesome'String Operations my string * 2'thisStringIsAwesomethisStringIsAwesome' my string 'Innit''thisStringIsAwesomeInnit' 'm' in my stringTrueMachine learningScientific computing2D plottingFree IDE that is includedwith AnacondaLeading open data science platformpowered by PythonCreate and sharedocuments with live code,visualizations, text, .Numpy ArraysAlso see ListsSelecting Numpy Array ElementsSubset my array[1]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 0Select item at index 1Slice my array[0:2]Select items at index 0 and 1array([1, 2])Subset 2D Numpy arrays my 2darray[:,0]my 2darray[rows, columns]array([1, 4])Numpy Array Operations my array 3array([False, False, False, my array * 2True], dtype bool)array([2, 4, 6, 8]) my array np.array([5, 6, 7, 8])array([6, 8, 10, 12])Strings my string 'thisStringIsAwesome' my stringData analysisInstall Python2List Methods Import libraries import numpy import numpy as npSelective import from math import pi my list [1, 2, 3, 4] my array np.array(my list) my 2darray np.array([[1,2,3],[4,5,6]])List OperationsTrueTypes and Type ConversionLibrariesString OperationsIndex starts at 0 my string[3] my string[4:9]String Methods String to uppercasemy string.upper()String to lowercasemy string.lower()Count String elementsmy string.count('w')my string.replace('e', 'i') Replace String elementsmy string.strip()Strip whitespacesNumpy Array Functions my array.shapenp.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)DataCampGet the dimensions of the arrayAppend items to an arrayInsert items in an arrayDelete items in an arrayMean of the arrayMedian of the arrayCorrelation coefficientStandard deviationLearn Python for Data Science Interactively