Di v e into P y thon IN TR OD U C TION TO DATA SC IE N C E IN P YTH ON Hillar y Green - Lerman Lead Data Scientist , Looker
What y o u' ll learn Ho w to w rite and e x ec u te P y thon code w ith DataCamp Ho w to load data from a spreadsheet Ho w to t u rn data into bea u tif u l plots INTRODUCTION TO DATA SCIENCE IN PYTHON
Sol v ing a m y ster y w ith data INTRODUCTION TO DATA SCIENCE IN PYTHON
Using the IP y thon shell INTRODUCTION TO DATA SCIENCE IN PYTHON
Using the script editor INTRODUCTION TO DATA SCIENCE IN PYTHON
What is a mod u le ? Gro u ps related tools together Makes it eas y to kno w w here to look for a partic u lar tool Common e x amples : matplotlib pandas scikit-learn scipy nltk INTRODUCTION TO DATA SCIENCE IN PYTHON
Importing pandas and matplotlib import pandas as pd from matplotlib import pyplot as plt # Pandas loads our data df = pd.read_csv('ransom.csv') # Matplotlib plots and displays plt.plot(df.letters, df.frequency) plt.show() INTRODUCTION TO DATA SCIENCE IN PYTHON
Importing a mod u le Importing a Mod u le import pandas Importing a mod u le w ith an alias import pandas as pd INTRODUCTION TO DATA SCIENCE IN PYTHON
Let ' s practice ! IN TR OD U C TION TO DATA SC IE N C E IN P YTH ON
Creating v ariables IN TR OD U C TION TO DATA SC IE N C E IN P YTH ON Hillar y Green - Lerman Lead Data Scientist , Looker
Filing a missing p u pp y report name = "Bayes" height = 24 weight = 75.5 INTRODUCTION TO DATA SCIENCE IN PYTHON
R u les for v ariable names M u st start w ith a le � er No spaces or special (u s u all y lo w ercase ) characters Case sensiti v e ( my_var is A � er � rst le � er , can u se di � erent from MY_VAR ) le � ers / n u mbers /u nderscores # Valid Variables # Invalid Variables bayes_weight bayes-height b bayes! bayes42 42bayes INTRODUCTION TO DATA SCIENCE IN PYTHON
Error messages bayes-height = 3 File "<stdin>", line 1 bayes-height = 3 ^ SyntaxError: can't assign to operator INTRODUCTION TO DATA SCIENCE IN PYTHON
Floats and strings � oat : represents an integer or decimal n u mber height = 24 weight = 75.5 string : represents te x t ; can contain le � ers , n u mbers , spaces , and special characters name = 'Bayes' breed = "Golden Retriever" INTRODUCTION TO DATA SCIENCE IN PYTHON
Common string mistakes Don ' t forget to u se q u otes ! Witho u t q u otes , y o u' ll get a name error . owner = DataCamp File "<stdin>", line 1, in <module> owner = DataCamp NameError: name 'DataCamp' is not defined Use the same t y pe of q u otation mark . If y o u start w ith a single q u ote , and end w ith a do u ble q u ote , y o u' ll get a s y nta x error . fur_color = "blonde' File "<stdin>", line 1 fur_color = "blonde' ^ INTRODUCTION TO DATA SCIENCE IN PYTHON
Displa y ing v ariables name = "Bayes" height = 24 weight = 75 print(height) 24 INTRODUCTION TO DATA SCIENCE IN PYTHON
Let ' s practice ! IN TR OD U C TION TO DATA SC IE N C E IN P YTH ON
What is a f u nction ? IN TR OD U C TION TO DATA SC IE N C E IN P YTH ON Hillar y Green - Lerman Lead Data Scientist , Looker
A f u nction is an action INTRODUCTION TO DATA SCIENCE IN PYTHON
F u nctions in code import pandas as pd from matplotlib import pyplot as plt df = pd.read_csv('letter_frequency.csv') plt.plot(df.letter_index, df.frequency, label='Ransom') plt.show() F u nctions perform actions : pd.read_csv() t u rns a cs v � le into a table in P y thon plt.plot() t u rns data into a line plot plt.show() displa y s plot in a ne w w indo w INTRODUCTION TO DATA SCIENCE IN PYTHON
INTRODUCTION TO DATA SCIENCE IN PYTHON
Anatom y of a f u nction : f u nction name F u nction Name : Starts w ith the mod u le that the f u nction " li v es " in ( plt ) Follo w ed b y the name of the f u nction ( plot ) F u nction name is al w a y s follo w ed b y parentheses () INTRODUCTION TO DATA SCIENCE IN PYTHON
Anatom y of a f u nction : positional arg u ments Positional Arg u ments : These are inp u ts to a f u nction ; the y tell the f u nction ho w to do its job Order ma � ers ! INTRODUCTION TO DATA SCIENCE IN PYTHON
Anatom y of a f u nction : ke yw ord arg u ments Ke yw ord Arg u ments : M u st come a � er positional arg u ments Start w ith the name of the arg u ment ( label ), then an eq u als sign ( = ) Follo w ed b y the arg u ment ( Ransom ) INTRODUCTION TO DATA SCIENCE IN PYTHON
Common f u nction errors Missing commas bet w een arg u ments Missing closed parenthesis INTRODUCTION TO DATA SCIENCE IN PYTHON
Let ' s practice ! IN TR OD U C TION TO DATA SC IE N C E IN P YTH ON
Recommend
More recommend