├── 1_Python Basic_1_The Python Interface.py ├── 1_Python Basic_2_Any comments.py ├── 1_Python Basic_3_Python as a calculator.py ├── 1_Python Basic_4_Variable Assignment.py ├── 1_Python Basic_5_Calculations with variables.py ├── 1_Python Basic_6_Other variable types.py ├── 1_Python Basic_7_Operations with other types.py ├── 1_Python Basic_8_Type conversion.py ├── 2_Python List_10_Inner workings of lists.py ├── 2_Python List_1_Create a list.py ├── 2_Python List_2_Create list with different types.py ├── 2_Python List_3_List of lists.py ├── 2_Python List_4_Subset and conquer.py ├── 2_Python List_5_Subset and calculate.py ├── 2_Python List_6_Slicing and dicing.py ├── 2_Python List_7_Slicing and dicing (2).py ├── 2_Python List_8_Replace list elements.py ├── 2_Python List_9_Extend a list.py ├── 3_Functions-and-packages_1_Familiar functions.py ├── 3_Functions-and-packages_2_Multiple arguments.py ├── 3_Functions-and-packages_3_String Methods.py ├── 3_Functions-and-packages_4_List Methods.py ├── 3_Functions-and-packages_5_List Methods (2).py ├── 3_Functions-and-packages_6_Import package.py ├── 3_Functions-and-packages_7_Selective import.py ├── 4_NumPy_10_Average versus median.py ├── 4_NumPy_11_Explore the baseball data.py ├── 4_NumPy_12_Blend it all together.py ├── 4_NumPy_1_First NumPy Array.py ├── 4_NumPy_2_Baseball players' height.py ├── 4_NumPy_3_Baseball player's BMI.py ├── 4_NumPy_4_Lightweight baseball players.py ├── 4_NumPy_5_Subsetting NumPy Arrays.py ├── 4_NumPy_6_First 2D NumPy Array.py ├── 4_NumPy_7_Baseball data in 2D form.py ├── 4_NumPy_8_Subsetting 2D NumPy Arrays.py ├── 4_NumPy_9_2D Arithmetic.py └── README.md /1_Python Basic_1_The Python Interface.py: -------------------------------------------------------------------------------- 1 | # Example, do not modify! 2 | print(5 / 8) 3 | print(7+10) 4 | # Put code below here 5 | -------------------------------------------------------------------------------- /1_Python Basic_2_Any comments.py: -------------------------------------------------------------------------------- 1 | # Just testing division 2 | print(5 / 8) 3 | 4 | # Addition works too 5 | print(7 + 10) -------------------------------------------------------------------------------- /1_Python Basic_3_Python as a calculator.py: -------------------------------------------------------------------------------- 1 | # Addition and subtraction 2 | print(5 + 5) 3 | print(5 - 5) 4 | 5 | # Multiplication and division 6 | print(3 * 5) 7 | print(10 / 2) 8 | 9 | # Exponentiation 10 | print(4 ** 2) 11 | 12 | # Modulo 13 | print(18 % 7) 14 | 15 | # How much is your $100 worth after 7 years? 16 | print(100*(1.1**7)) -------------------------------------------------------------------------------- /1_Python Basic_4_Variable Assignment.py: -------------------------------------------------------------------------------- 1 | # Create a variable savings 2 | savings = 100 3 | 4 | # Print out savings 5 | print(savings) -------------------------------------------------------------------------------- /1_Python Basic_5_Calculations with variables.py: -------------------------------------------------------------------------------- 1 | # Create a variable savings 2 | savings = 100 3 | 4 | # Create a variable factor 5 | factor=1.10 6 | 7 | # Calculate result 8 | result=savings * factor ** 7 9 | 10 | # Print out result 11 | print(result) -------------------------------------------------------------------------------- /1_Python Basic_6_Other variable types.py: -------------------------------------------------------------------------------- 1 | # Create a variable desc 2 | desc="compound interest" 3 | 4 | # Create a variable profitable 5 | profitable = True -------------------------------------------------------------------------------- /1_Python Basic_7_Operations with other types.py: -------------------------------------------------------------------------------- 1 | # Several variables to experiment with 2 | savings = 100 3 | factor = 1.1 4 | desc = "compound interest" 5 | 6 | # Assign product of factor and savings to year1 7 | year1=savings*factor 8 | 9 | # Print the type of year1 10 | print(type(year1)) 11 | 12 | # Assign sum of desc and desc to doubledesc 13 | doubledesc=desc+desc 14 | 15 | # Print out doubledesc 16 | print(doubledesc) -------------------------------------------------------------------------------- /1_Python Basic_8_Type conversion.py: -------------------------------------------------------------------------------- 1 | # Definition of savings and result 2 | savings = 100 3 | result = 100 * 1.10 ** 7 4 | 5 | # Fix the printout 6 | print("I started with $" + str(savings) + " and now have $" + str(result) + ". Awesome!") 7 | 8 | # Definition of pi_string 9 | pi_string = "3.1415926" 10 | 11 | # Convert pi_string into float: pi_float 12 | pi_float=float(pi_string) -------------------------------------------------------------------------------- /2_Python List_10_Inner workings of lists.py: -------------------------------------------------------------------------------- 1 | # Create list areas 2 | areas = [11.25, 18.0, 20.0, 10.75, 9.50] 3 | 4 | # Create areas_copy 5 | areas_copy = [11.25, 18.0, 20.0, 10.75, 9.50] 6 | 7 | # Change areas_copy 8 | areas_copy[0] = 5.0 9 | 10 | # Print areas 11 | print(areas) -------------------------------------------------------------------------------- /2_Python List_1_Create a list.py: -------------------------------------------------------------------------------- 1 | # area variables (in square meters) 2 | hall = 11.25 3 | kit = 18.0 4 | liv = 20.0 5 | bed = 10.75 6 | bath = 9.50 7 | 8 | # Create list areas 9 | areas=[11.25,18.0,20.0,10.75,9.50] 10 | 11 | # Print areas 12 | print(areas) 13 | -------------------------------------------------------------------------------- /2_Python List_2_Create list with different types.py: -------------------------------------------------------------------------------- 1 | # area variables (in square meters) 2 | hall = 11.25 3 | kit = 18.0 4 | liv = 20.0 5 | bed = 10.75 6 | bath = 9.50 7 | 8 | # Adapt list areas 9 | areas = ["hallway",hall,"kitchen", kit, "living room", liv,"bedroom", bed, "bathroom", bath] 10 | 11 | # Print areas 12 | print(areas) -------------------------------------------------------------------------------- /2_Python List_3_List of lists.py: -------------------------------------------------------------------------------- 1 | # area variables (in square meters) 2 | hall = 11.25 3 | kit = 18.0 4 | liv = 20.0 5 | bed = 10.75 6 | bath = 9.50 7 | 8 | # house information as list of lists 9 | house = [["hallway", hall], 10 | ["kitchen", kit], 11 | ["living room", liv],["bedroom",bed],["bathroom",bath]] 12 | 13 | # Print out house 14 | print(house) 15 | 16 | # Print out the type of house 17 | print(type(house)) -------------------------------------------------------------------------------- /2_Python List_4_Subset and conquer.py: -------------------------------------------------------------------------------- 1 | # Create the areas list 2 | areas = ["hallway", 11.25, "kitchen", 18.0, "living room", 20.0, "bedroom", 10.75, "bathroom", 9.50] 3 | 4 | # Print out second element from areas 5 | print(areas[1]) 6 | 7 | # Print out last element from areas 8 | print(areas[-1]) 9 | 10 | # Print out the area of the living room 11 | print(areas[5]) -------------------------------------------------------------------------------- /2_Python List_5_Subset and calculate.py: -------------------------------------------------------------------------------- 1 | # Create the areas list 2 | areas = ["hallway", 11.25, "kitchen", 18.0, "living room", 20.0, "bedroom", 10.75, "bathroom", 9.50] 3 | 4 | # Sum of kitchen and bedroom area: eat_sleep_area 5 | eat_sleep_area = areas[3]+areas[-3] 6 | 7 | # Print the variable eat_sleep_area 8 | print(eat_sleep_area) -------------------------------------------------------------------------------- /2_Python List_6_Slicing and dicing.py: -------------------------------------------------------------------------------- 1 | # Create the areas list 2 | areas = ["hallway", 11.25, "kitchen", 18.0, "living room", 20.0, "bedroom", 10.75, "bathroom", 9.50] 3 | 4 | # Use slicing to create downstairs 5 | downstairs =areas[:6] 6 | 7 | # Use slicing to create upstairs 8 | upstairs=areas[6:] 9 | 10 | # Print out downstairs and upstairs 11 | print(downstairs) 12 | print(upstairs) -------------------------------------------------------------------------------- /2_Python List_7_Slicing and dicing (2).py: -------------------------------------------------------------------------------- 1 | # Create the areas list 2 | areas = ["hallway", 11.25, "kitchen", 18.0, "living room", 20.0, "bedroom", 10.75, "bathroom", 9.50] 3 | 4 | # Alternative slicing to create downstairs 5 | downstairs=areas[:6] 6 | 7 | # Alternative slicing to create upstairs 8 | upstairs=areas[6:] -------------------------------------------------------------------------------- /2_Python List_8_Replace list elements.py: -------------------------------------------------------------------------------- 1 | # Create the areas list 2 | areas = ["hallway", 11.25, "kitchen", 18.0, "living room", 20.0, "bedroom", 10.75, "bathroom", 9.50] 3 | 4 | # Correct the bathroom area 5 | areas[9] =10.50 6 | 7 | # Change "living room" to "chill zone" 8 | areas[4]="chill zone" -------------------------------------------------------------------------------- /2_Python List_9_Extend a list.py: -------------------------------------------------------------------------------- 1 | # Create the areas list and make some changes 2 | areas = ["hallway", 11.25, "kitchen", 18.0, "chill zone", 20.0, 3 | "bedroom", 10.75, "bathroom", 10.50] 4 | 5 | # Add poolhouse data to areas, new list is areas_1 6 | areas_1 = areas + ["poolhouse", 24.5] 7 | 8 | # Add garage data to areas_1, new list is areas_2 9 | areas_2 = areas_1 + ["garage",15.45] -------------------------------------------------------------------------------- /3_Functions-and-packages_1_Familiar functions.py: -------------------------------------------------------------------------------- 1 | # Create variables var1 and var2 2 | var1 = [1, 2, 3, 4] 3 | var2 = True 4 | 5 | # Print out type of var1 6 | print(type(var1)) 7 | 8 | # Print out length of var1 9 | print(len(var1)) 10 | 11 | # Convert var2 to an integer: out2 12 | out2=int(var2) -------------------------------------------------------------------------------- /3_Functions-and-packages_2_Multiple arguments.py: -------------------------------------------------------------------------------- 1 | # Create lists first and second 2 | first = [11.25, 18.0, 20.0] 3 | second = [10.75, 9.50] 4 | 5 | # Paste together first and second: full 6 | full = first+second 7 | 8 | # Sort full in descending order: full_sorted 9 | full_sorted = sorted(full,reverse=True) 10 | 11 | # Print out full_sorted 12 | print(full_sorted) -------------------------------------------------------------------------------- /3_Functions-and-packages_3_String Methods.py: -------------------------------------------------------------------------------- 1 | # string to experiment with: room 2 | room = "poolhouse" 3 | 4 | # Use upper() on room: room_up 5 | room_up=room.upper() 6 | 7 | # Print out room and room_up 8 | print(room) 9 | print(room_up) 10 | # Print out the number of o's in room 11 | print(room.count('o')) -------------------------------------------------------------------------------- /3_Functions-and-packages_4_List Methods.py: -------------------------------------------------------------------------------- 1 | # Create list areas 2 | areas = [11.25, 18.0, 20.0, 10.75, 9.50] 3 | 4 | # Print out the index of the element 20.0 5 | print(areas.index(20.0)) 6 | 7 | # Print out how often 14.5 appears in areas 8 | print(areas.count(14.5)) 9 | -------------------------------------------------------------------------------- /3_Functions-and-packages_5_List Methods (2).py: -------------------------------------------------------------------------------- 1 | # Create list areas 2 | areas = [11.25, 18.0, 20.0, 10.75, 9.50] 3 | 4 | # Use append twice to add poolhouse and garage size 5 | areas.append(24.5) 6 | areas.append(15.45) 7 | 8 | # Print out areas 9 | print(areas) 10 | 11 | # Reverse the orders of the elements in areas 12 | areas.reverse() 13 | 14 | # Print out areas 15 | print(areas) -------------------------------------------------------------------------------- /3_Functions-and-packages_6_Import package.py: -------------------------------------------------------------------------------- 1 | # Definition of radius 2 | r = 0.43 3 | # Import the math package 4 | import math 5 | 6 | # Calculate C 7 | C = 2*math.pi*r 8 | 9 | # Calculate A 10 | A = math.pi*r*r 11 | 12 | # Build printout 13 | print("Circumference: " + str(C)) 14 | print("Area: " + str(A)) -------------------------------------------------------------------------------- /3_Functions-and-packages_7_Selective import.py: -------------------------------------------------------------------------------- 1 | # Definition of radius 2 | r = 192500 3 | 4 | # Import radians function of math package 5 | from math import radians 6 | 7 | # Travel distance of Moon over 12 degrees. Store in dist. 8 | phi=radians(12) 9 | dist=r*phi 10 | 11 | # Print out dist 12 | print(dist) -------------------------------------------------------------------------------- /4_NumPy_10_Average versus median.py: -------------------------------------------------------------------------------- 1 | # np_baseball is available 2 | 3 | # Import numpy 4 | import numpy as np 5 | 6 | # Create np_height from np_baseball 7 | np_height_in=np_baseball[:,0] 8 | 9 | # Print out the mean of np_height 10 | print(np.mean(np_height_in)) 11 | 12 | # Print out the median of np_height 13 | print(np.median(np_height_in)) 14 | -------------------------------------------------------------------------------- /4_NumPy_11_Explore the baseball data.py: -------------------------------------------------------------------------------- 1 | # np_baseball is available 2 | 3 | # Import numpy 4 | import numpy as np 5 | 6 | # Print mean height (first column) 7 | avg = np.mean(np_baseball[:,0]) 8 | print("Average: " + str(avg)) 9 | 10 | # Print median height. Replace 'None' 11 | med = np.median(np_baseball[:,0]) 12 | print("Median: " + str(med)) 13 | 14 | # Print out the standard deviation on height. Replace 'None' 15 | stddev = np.std(np_baseball[:,0]) 16 | print("Standard Deviation: " + str(stddev)) 17 | 18 | # Print out correlation between first and second column. Replace 'None' 19 | corr = np.corrcoef(np_baseball[:,0], np_baseball[:,1]) 20 | print("Correlation: " + str(corr)) -------------------------------------------------------------------------------- /4_NumPy_12_Blend it all together.py: -------------------------------------------------------------------------------- 1 | # heights and positions are available as lists 2 | 3 | # Import numpy 4 | import numpy as np 5 | 6 | # Convert positions and heights to numpy arrays: np_positions, np_heights 7 | np_positions=np.array(positions) 8 | np_heights=np.array(heights) 9 | 10 | 11 | # Heights of the goalkeepers: gk_heights 12 | gk_heights = np_heights[np_positions=='GK'] 13 | 14 | # Heights of the other players: other_heights 15 | np_positions !='GK' 16 | other_heights=np_heights[np_positions !='GK'] 17 | 18 | # Print out the median height of goalkeepers. Replace 'None' 19 | print("Median height of goalkeepers: " + str(np.median(gk_heights))) 20 | 21 | # Print out the median height of other players. Replace 'None' 22 | print("Median height of other players: " + str(np.median(other_heights))) -------------------------------------------------------------------------------- /4_NumPy_1_First NumPy Array.py: -------------------------------------------------------------------------------- 1 | # Create list baseball 2 | baseball = [180, 215, 210, 210, 188, 176, 209, 200] 3 | 4 | # Import the numpy package as np 5 | import numpy as np 6 | 7 | # Create a numpy array from baseball: np_baseball 8 | np_baseball=np.array(baseball) 9 | 10 | # Print out type of np_baseball 11 | print(type(np_baseball)) -------------------------------------------------------------------------------- /4_NumPy_2_Baseball players' height.py: -------------------------------------------------------------------------------- 1 | # height is available as a regular list 2 | 3 | # Import numpy 4 | import numpy as np 5 | 6 | # Create a numpy array from height: np_height 7 | np_height=np.array(height_in) 8 | 9 | # Print out np_height 10 | print(np_height) 11 | 12 | # Convert np_height to m: np_height_m 13 | np_height_m=np_height*0.0254 14 | # Print np_height_m 15 | print(np_height_m) 16 | -------------------------------------------------------------------------------- /4_NumPy_3_Baseball player's BMI.py: -------------------------------------------------------------------------------- 1 | # height and weight are available as a regular lists 2 | 3 | # Import numpy 4 | import numpy as np 5 | 6 | # Create array from height with correct units: np_height_m 7 | np_height_m = np.array(height_in) * 0.0254 8 | 9 | # Create array from weight with correct units: np_weight_kg 10 | np_weight_kg=np.array(weight_lb)*0.453592 11 | 12 | # Calculate the BMI: bmi 13 | bmi=np_weight_kg/(np_height_m **2) 14 | 15 | # Print out bmi 16 | print(bmi) 17 | -------------------------------------------------------------------------------- /4_NumPy_4_Lightweight baseball players.py: -------------------------------------------------------------------------------- 1 | # height and weight are available as a regular lists 2 | 3 | # Import numpy 4 | import numpy as np 5 | 6 | # Calculate the BMI: bmi 7 | np_height_m = np.array(height) * 0.0254 8 | np_weight_kg = np.array(weight) * 0.453592 9 | bmi = np_weight_kg / np_height_m ** 2 10 | 11 | # Create the light array 12 | light=bmi<21 13 | 14 | # Print out light 15 | print(light) 16 | 17 | # Print out BMIs of all baseball players whose BMI is below 21 18 | print(bmi[light]) -------------------------------------------------------------------------------- /4_NumPy_5_Subsetting NumPy Arrays.py: -------------------------------------------------------------------------------- 1 | # height and weight are available as a regular lists 2 | 3 | # Import numpy 4 | import numpy as np 5 | 6 | # Store weight and height lists as numpy arrays 7 | np_weight_lb = np.array(weight_lb) 8 | np_height_in = np.array(height_in) 9 | 10 | # Print out the weight at index 50 11 | print(np_weight_lb[50]) 12 | # Print out sub-array of np_height: index 100 up to and including index 110 13 | print(np_height_in[100:111]) 14 | -------------------------------------------------------------------------------- /4_NumPy_6_First 2D NumPy Array.py: -------------------------------------------------------------------------------- 1 | # Create baseball, a list of lists 2 | baseball = [[180, 78.4], 3 | [215, 102.7], 4 | [210, 98.5], 5 | [188, 75.2]] 6 | 7 | # Import numpy 8 | import numpy as np 9 | 10 | # Create a 2D numpy array from baseball: np_baseball 11 | np_baseball=np.array(baseball) 12 | # Print out the type of np_baseball 13 | print(type(np_baseball)) 14 | 15 | # Print out the shape of np_baseball 16 | print(np_baseball.shape) -------------------------------------------------------------------------------- /4_NumPy_7_Baseball data in 2D form.py: -------------------------------------------------------------------------------- 1 | # baseball is available as a regular list of lists 2 | 3 | # Import numpy package 4 | import numpy as np 5 | 6 | # Create a 2D numpy array from baseball: np_baseball 7 | np_baseball=np.array(baseball) 8 | 9 | # Print out the shape of np_baseball 10 | print(np_baseball.shape) -------------------------------------------------------------------------------- /4_NumPy_8_Subsetting 2D NumPy Arrays.py: -------------------------------------------------------------------------------- 1 | # baseball is available as a regular list of lists 2 | 3 | # Import numpy package 4 | import numpy as np 5 | 6 | # Create np_baseball (2 cols) 7 | np_baseball = np.array(baseball) 8 | 9 | # Print out the 50th row of np_baseball 10 | print(np_baseball[49,:]) 11 | 12 | # Select the entire second column of np_baseball: np_weight 13 | np_weight_lb =np_baseball[:,1] 14 | # Print out height of 124th player 15 | print(np_baseball[123, 0]) 16 | -------------------------------------------------------------------------------- /4_NumPy_9_2D Arithmetic.py: -------------------------------------------------------------------------------- 1 | # baseball is available as a regular list of lists 2 | # updated is available as 2D numpy array 3 | 4 | # Import numpy package 5 | import numpy as np 6 | 7 | # Create np_baseball (3 cols) 8 | np_baseball = np.array(baseball) 9 | 10 | # Print out addition of np_baseball and updated 11 | print(np_baseball+updated) 12 | # Create numpy array: conversion 13 | conversion=np.array([0.0254,0.453592,1]) 14 | 15 | # Print out product of np_baseball and conversion 16 | print(np_baseball * conversion) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Datacamp-Intro-to-Python-For-Data-Science --------------------------------------------------------------------------------