Python for Data Science, Essential Training Part 1

6.2 Hours

3/28/2021 - 5/24/2021


Course sections: Filter-Group-Sort | Data Visualization | Math Statistics | Web Scraping



Python for Data Science Essential Training is one of the most popular data science courses at LinkedIn Learning. It has now been updated and expanded to two parts-for even more hands-on experience with Python. In this course, instructor Lillian Pierson takes you step by step through a practical data science project: a web scraper that downloads and analyzes data from the web. Along the way, she introduces techniques to clean, reformat, transform, and describe raw data; generate visualizations; remove outliers; perform simple data analysis; and generate interactive graphs using the Plotly library.

Instructor

Lillian Pierson, P.E.
  • Lillian Pierson, P.E. is a leading expert in the field of big data and data science.

As the Founder of Data-Mania LLC, Lillian offers online and face-to-face training courses, as well as workshops and other educational materials in the area of big data, data science, and data analytics.


1. Introduction to the data professions 9m 7s

The four flavors of data analysis 3m 16s

  • Data analysis

  • Data science

  • Artificial intelligence

  • Machine learning

Prediction is where you do the predictive modeling within data science

Execution is the autonomous response from the engineered systems.

  • Deep learning

Set of predictive methodologies.

Why use Python for analytics? 4m 22s

  • vs R, Julia, Go

  • Advanced Data Analysis: NumPy, SciPy, pandas

  • Data visualization: Matplotlib, Seaborn

  • Machine learning: scikit-learn, TensorFlow (DeepLearn), Keras (DeepLearn)

High-level course road map 1m 28s


2. Data preparation basics


  # Save workbook as HTML
  import os
  os.system('jupyter nbconvert --to html 1_filter_select.ipynb')

I. Filtering and selecting 15m 25s

   numpy - basis for several python data science tools.

   pandas- fast clean, prep, analysis; visualization; machine learn.

  • built on NumPy; arrays (series), matrices (dataframes)

  • index with [] or .loc[]

      DF_obj.loc[['row 2', 'row 5'], ['col 5', 'col 2']]
  • Series object is a single row or col that is indexed; DataFrame is a matrix of indices and columns.
      pd.Series(np.arange(2), index=['row 1', 'row 2'])
      
      pd.DataFrame(np.random.rand(36).reshape((6,6)),
                         index=['row 1', 'row 2'],
                         columns=['col 1', 'col 2'])
  • plain indexing
      pd.series_obj[0,7]        # Get values.  
      
      pd.series_obj[[0,7]]       # Get label index and value. 
  • data slicing with “:”
      series_obj['row 3' : 'row 7']
  • filtering
      series_obj[series_obj > 6]
  • arith comparison
  jupyter notebook
  
  win: shft+enter
  mac: shft+return

II. Treating missing values 15m 9s
  • Missing values: NaN = not a number

  • Drop 0s, 99s, 999s

        np.nan
        
        pd.Series.isnull()
  • fillna method
        pd.DataFrame.fillna(0)
        
        pd.DataFrame.fillna({0: 0.1, 5: 1.25}) - Fill column 0 na's with 0.1; fill column 5 na's with 1.25.
        
        pd.DataFrame.fillna(method='ffill') - Forward fill all na's.  
  • DataFrame - Dealing with nulls: isnull() and dropna()
        pd.DataFrame.loc[3:5,0] = np.nan - Manually set DF cells with loc[] cmd.
        
        pd.DataFrame.isnull().sum() - Get column-wise counts of null values.
        
        pd.DataFrame.dropna() - Drop all rows with na's.
        
        pd.DataFrame.dropna(axis=1) - Drop all cols with na's.

III. Removing duplicates 6m 18s
  • Maintain consistent datasets

  • Avoid erroneous or misleading statistics

  • Find duplicates | duplicated() and drop_duplicates()

        pd.DataFrame.duplicated()     # List row #'s with duplicated values

        pd.DataFrame.drop_duplicates()     # Drop row #'s with duplicated values
        
        pd.DataFrame.drop_duplicates(['col 3']) # Index label

IV. Concatenating and transforming 10m 8s
  • pd.concat([DF_obj, DF_obj2]) # join rows

  • pd.concat([DF_obj, DF_obj2], axis=1) # join columns

  • DF_obj.drop([0, 2]) # drop row 0 and 2

  • DF_obj.drop([0, 2], axis=1) # drop col 0 and 2


Add new column - join()

        series_obj = Series(np.arange(6))

        series_obj.name = "Age"

        DataFrame.join(DF_obj, series_obj)

Add new rows - append()

        DF_obj.append(DF_obj2, ignore_index=True)

Sort data - sort_values()

        # Sort col 5 in descending order
        
        DF_obj.sort_values(by=(5), ascending=False)

V. Grouping and aggregation 4m 52s
  • Compare subsets

  • Deduce why subgroups differ

  • Subset for analysis


Read CSV - read_csv() and head()

        cars = pd.read_csv("C:\py_data\mtcars.csv")
        
        cars.columns = ['car_names', 'mpg', 'cyl', 'disp', 'hp', 'drat', 'wt', 'qsec', 'vs', 'am', 'gear', 'carb']
        
        cars.head()

Group by col index - groupby()

        cars_groups = cars.groupby(['cyl'])
        
        cars_groups.mean()

Subset cols - [[‘c1’, ‘c2’]]

        cars_subset = cars[['mpg', 'disp', 'hp', 'wt']]
        
        cars_subset.head()

3. Data Visualization 101

The three types of data visualization 7m 40s

Selecting optimal data graphics 6m 17s

Communicating with color and context 4m 38s


4. Practical Data Visualization

Creating standard data graphics 8m 42s

Defining elements of a plot 9m 6s

Plot formatting 12m 8s

Creating labels and annotations 14m 30s

Visualizing time series 6m 33s

Creating statistical data graphics 9m 59s


5. Basic math and statistics

Simple arithmetic 6m 53s

Basic linear algebra 6m 17s

Generating summary statistics 9m 46s

Summarizing categorical data 12m 25s

Parametric correlation analysis 15m 15s

Non-parametric correlation analysis 13m 25s

Transforming dataset distributions 9m 54s

Extreme value analysis for outliers 11m 5s

Multivariate analysis for outliers 5m 53s


6. Data Sourcing via web scraping

BeautifulSoup object 18m 28s

NavigableString objects 10m 1s

Data parsing 12m 42s

Web scraping in practice 10m 48s

Introduction to NLP 12m 31s

Cleaning and stemming textual data 7m 47s

Lemmatizing and analyzing textual data 10m 15s


7. Collaborative Analytics with Plotly

Introduction to Plotly 4m 31s

Create statistical charts 3m 28s

Line charts in Plotly 6m 29s

Bar charts and pie charts in Plotly 7m 24s

Create statistical charts 15m


  1. Conclusion