Every Beginner Data Scientist Should Understand This

Dave Ebbelaar · Beginner ·🧘 Mental Health & Wellbeing Practice ·3y ago

Key Takeaways

This video covers the basics of Python package management, library dependencies, and prompt engineering, demonstrating tools like pip, pandas, scikit-learn, and GitHub, with a focus on importing modules, creating and manipulating files, and working with code in an IDE versus a notebook.

Full Transcript

do you really understand what happens when you're on pip install pandas if not then this video is for you so this is definitely something that I wish I understood earlier in my data science career because it just overall helps you to write better code work better with external libraries so I want to talk about files modules classes and functions for the Python programming language if I for example come over to visual studio code and I do a standard import like import pandas SPD but do you know that when you import the pandas Library you actually import a whole set of files that is underlying that Library so you can see how I can click on the module basically that I am importing over here and look at all the code that is behind there and this can be really convenient when you're trying to look up documentation see how a library or a class works so that is really what I want to briefly cover in this video how to work with that because for me it took a very long time to figure out that you can actually click through on all your functions modules classes and actually figure out what's going on behind the scenes in the back end basically and this can really help you to not have to constantly switch to stack Overflow to try and find out what for example the specific parameters are for a certain machine learning model from scikit-learn for example so let's start from the very Basics what happens when you run pip install so when you do this you basically reference the python package index and that is just a large repository a large Library basically of all the PIP packages that are available so for example I can search for pandas over here and here I can see pandas2 and you can see how you can pip install panda to or just the original pandas pip install pandas and from here you can also go to the home page or also to for example the source code so here you can basically see what the pandas library is what it contains and usually when you work like in your code editor for example and you go to let me open up a new terminal over here and you do a pip install so for example I do a pip install pandas within this environment it's already installed but usually you don't really understand what's going on because you are looking up these tutorials and you see oh if you want to use this package just do a quick pip install but what is happening in the background is that your pip basically is referencing to a certain GitHub repository where all the code lives where everything is and it pulls that code onto your machine so now when I for example I import the pandas library and again I can click on this module over here by if I own Mac if I press command and if I'm on Windows you can press control and then basically see what's going on over there and then from here I can right click this file and I can refill it in the finder or the windows equivalent would be to refill it in the Explorer and I can basically see that I am here in a bunch of files and I am now in the init file from the pandas library that you can see over here and if we scroll a little back to see what's going on you can see that we are currently in a conda environment so this is a specific environment that I created for this project and here you can see all the various contact environments that I have and in that environment is a lip folder and in there is a python folder so I am using python 3.8 in this case and then over here are the side packages and here you can basically see all the packages that I have installed using pip and also like all the dependencies so usually what happens if you install for example pandas the pandas Library also requires some other packages and it will download those as well and it will basically all put it into this folder over here so that is basically what happens when you run a simple pip install it downloads the files from a GitHub repository and puts it onto your local drive so let's look at a few more examples to fully understand this so let's consider the scikit-learn library which you can install using pip install site alert then once I import that Library I can have a look at the finder over here and see basically what it's all about so here their top level we can see the scikit learn folder and in there are basically a bunch of other python files and also folders containing again other python files so coming back to the document over here basically when you load in or install that package you download many files including python files that Define the modules classes and functions and when Pip installs the package it places these files in appropriate directories on your drive so in my case that would be in the virtual environment or the conda environment I should say and then once we come back to our IDE for example our code editor and we load inside kitlearn we basically can import the modules classes and functions into our python script so basically when you run an import statement python looks for the corresponding dot Pi files on your drive reads the code in a file and creates new module objects in memory so what we are essentially doing over here is we are referencing to this folder over here and we basically tell python within that script that we have to load all of this information but usually you don't import the top level Library all the time so what often happens is that you import specific classes and now this would definitely be the case for scikit-learn so as I will show you in a bit for pandas for example it's pretty common to just import the whole Library so we just import pandas SPD but when when we are working with scikit-learn it is usually better to import specific classes and functions from this Library so what are all the differences between all the terms that I just described so we have files we have modules we have classes and we have functions and all of those work slightly different you use them in slightly different ways and scenarios so let's look at this again from the example of the scikit learn Library so the files so we already had a look at that so that is basically all the dot by file extensions that you see within the sklearn library that the modules so modules are a collection of related function classes and variables that are grouped together in a single file examples from scikit-learn are for example the pre-processing module that contains functions for data preprocessing tasks like scaling and normalization so let's have a quick look at pre-processing overhead so here we can see we have a folder which is called a module that has again python files and now what we can do if I for example come over here I can basically call the SK learn Library first then do a DOT and then do for example pre-processing and then we can import that whole module on its own so if I hover over here and I for example hit command and then look at it you can see that it is a module and you see description over here but I can also say that from this module I want to import a specific class instance in this example and that is for example the standard scalar so if I hover over here I can see that this is a class okay so this brings us to the next subject that is a class and a class is a blueprint for creating objects that have attributes variables and methods so for a lot of the terms that I'm using you will find out that people will use them interchangeably so methods functions are the same things attributes variables when it comes to a class are basically the same thing so keep that in mind so in the example over here so here is the example of a logistic regression class but we were looking specifically at the standard scalar class is if I go in here so this is the module you can see it over here in vs code and I can basically see everything that is in here so for example these standard scalar that is over here I can click through it and also find out where that is located so you see how in these files everything links and references each other basically and this is just Python's way of figuring out where everything is and how you can import them so we can have a look and so this is within the data dot by file and we were first in the init file so remember we went from standard scalar to the init file where the import is and then to the data file where we find the class over here and now we have also come to a point where working like this and looking through the classes and in a bit also the functions becomes really helpful because you can see that there is documentation in here so if you have a solid Library there is usually a good documentation string that basically describes first top level how a class works and then also going further into it even how the functions work but before we dive further into that let me also come back to the final topic and that is a function so functions are blocks of code that perform a specific task and can be called multiple types and then for example in the scikit-learn library we have metrics and we have the accuracy score so let me quickly import that so come back to the file over here and we say from Psychic learn and then metrics so two modules so first we have the dope level module which is basically the whole Library then we have the metrics and then what we can do is we can for example import mean squared error and now if I hover over here you can see this is a function and I can come in here and now I have the documentation over here of how this function works so I won't dive specifically into all the nuances when it comes to functions and classes that is a topic for another video but in general a function you define by using def you're probably aware of this if you have been working with python and data science for a while and a class is let me come back to for example the standard scalar class over here so you define a class simply by writing class and then you use camel case basically you capitalize every first letter of each word to be in line with the common python style guide so functions and classes and now where this gets really helpful is when you are actually start to work with these libraries so let me for example show you a model over here so let's import a random Forest regressor so instead of coming to Google over here and say like SK learn random forest and then take the regressor over here and then come to the documentation and then basically look up over here okay so it needs an estimator the Criterion and basically all the documentation everything that goes in there what you can now do is you can come over here and just click with command or control on this class and you can just scroll down and see basically everything that is on this page over here so you can see we have the Criterion you have the m estimators and you can usually if you scroll down you also have an example over here so I can literally come in here come back to my file and then just make sure to clean this up a little and we have an example so that is also something you typically find on a page over here but you can see how it's just the same and instead of switching constantly back and forth between your code editor your IDE and the documentation online it is already in here and specifically for the library that you're working with so when you are looking up stuff online you also have to be mindful not to like click this first hit and go to the random Force classifier now we're working with the random force regressor and you can't make that mistake if you just stay in your IDE so say you have this model you have the X and UI and you make predictions and now you want to calculate the mean squared error but you're thinking again okay what should go first and how should I name my variables you just come in here and it says Okay first it is y true and then it is why I predicted so not the other way around and then also you can see some examples over here so okay you can put a list in here or a numpy array and then it will work and like in the beginning of my data science career I would just work from Jupiter notebooks so I will do all my projects in here this that is also basically how I learned it in University but if you are just using jupyter notebooks within your browser you don't have the ability to do this so I can't I can't go in here now you can do that from vs code so that same notebook is within vs code and now I can click on that pandas library and go back so if you like to work with notebooks I would still recommend working with them in an IDE such as Visual Studio code and I know from experience that a lot of people work like this with just notebooks as well and you're just limiting yourself by not being able to look up the docs look up the documentation and constantly have to switch back and forth and find it out based basically like that and when you understand all of this you can also start to work within your own projects more dynamically so for example if I come to this new empty python file over here and I for example create a function over here so this is my awesome function and it will just do a simple print statement so let's save this in here and now I come back to my example and what I can now do in basically the same manner as I'm importing functions from the scikit-learn library for example I can say from functions import and now I can import my RSM function so see how now similar to how I would interact with the scikit-learn library I can also interact with my own files so as you can see understanding all of these Concepts so the files the modules the classes and the functions and how they work and interact with each other if you import them is really at the core of being an effective python programmer and like I've said when I started out I started working in single notebooks and just put all my code from top to bottom and that would be it and then later I transitioned to python files and then I would just write all of my code in one big file and I would of course use the import statements but I did not really know what was going on behind the scenes in the back end so I would just pip install pip install pip install and then look up the PIP libraries on the internet so go to the GitHub or the documentation and then learn how to work with them but as I've hopefully explained to you in this video there's a much better way to interact with your code all right and that's it for this video that is what I wanted to show you now if you found this video helpful then I would really appreciate it if you like this video subscribe to the channel That way you also let YouTube know that you want to see more content like this more data science content and that is of course helpful to you if you want to learn more about working with Fierce code and files and working like this basically then you should really check out this video next where I go through my entire setup and explain basically how you can work in a similar way as I do

Original Description

In this video, I'll be sharing with you everything you need to know about working with Python files, modules, classes, and functions. I'll show you how to create and manipulate files in Python, and how to import modules and use them in your code. We'll also discuss the importance of documentation and how to look up information in the official Python documentation. 👉🏻 Link to the document: https://docs.datalumina.io/pPLC5EZwDoYTAz ⏱️ Timestamps 00:00 Introduction 01:38 What happens when you run `pip install` 06:49 Files, modules, classes, and functions 09:38 Finding code documentation and examples 👋🏻 About Me Hey there, my name is @daveebbelaar I work as a freelance data scientist and coach. You've stumbled upon my YouTube channel, where I give away all my secrets when it comes to working with data. I'm not here to sell you any data course — everything you need is right here on YouTube. Making videos is my passion, and I've been doing it for 18 years. I just genuinely enjoy helping people. While I don't sell any data courses, I do offer a coaching program for data professionals looking to start their own freelance business. If that sounds like you, head over to https://www.datalumina.io/ to learn more about working with me and kick-starting your freelance career.
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Dave Ebbelaar · Dave Ebbelaar · 34 of 60

1 How to Install Homebrew on Mac (Getting Started)
How to Install Homebrew on Mac (Getting Started)
Dave Ebbelaar
2 How to Install Python on Mac (Homebrew)
How to Install Python on Mac (Homebrew)
Dave Ebbelaar
3 How to Install Anaconda on Mac (Getting Started)
How to Install Anaconda on Mac (Getting Started)
Dave Ebbelaar
4 How to Set up VS Code for Data Science & AI
How to Set up VS Code for Data Science & AI
Dave Ebbelaar
5 How to Use Git in VS Code for Data Science
How to Use Git in VS Code for Data Science
Dave Ebbelaar
6 Data Science Desk Setup to Maximize Productivity
Data Science Desk Setup to Maximize Productivity
Dave Ebbelaar
7 THIS Is How I Write Clean Data Science Code EVERY TIME
THIS Is How I Write Clean Data Science Code EVERY TIME
Dave Ebbelaar
8 Data Science Tutorial - Project Structure
Data Science Tutorial - Project Structure
Dave Ebbelaar
9 Changing rcParams for Better Data Science Plots | Matplotlib Tutorial
Changing rcParams for Better Data Science Plots | Matplotlib Tutorial
Dave Ebbelaar
10 How to Read Excel Files with Python (Pandas Tutorial)
How to Read Excel Files with Python (Pandas Tutorial)
Dave Ebbelaar
11 My Data Science Journey (Zero to Freelance)
My Data Science Journey (Zero to Freelance)
Dave Ebbelaar
12 How I Automate Data Visualization in Python
How I Automate Data Visualization in Python
Dave Ebbelaar
13 16 Apps I Use Daily as a Data Scientist
16 Apps I Use Daily as a Data Scientist
Dave Ebbelaar
14 How to Manage Conda Environments for Data Science
How to Manage Conda Environments for Data Science
Dave Ebbelaar
15 How to Export Machine Learning Models in Python
How to Export Machine Learning Models in Python
Dave Ebbelaar
16 VS Code Speed Hack for Data Science
VS Code Speed Hack for Data Science
Dave Ebbelaar
17 17 VS Code Tips That Will Change Your Data Science Workflow
17 VS Code Tips That Will Change Your Data Science Workflow
Dave Ebbelaar
18 How to Predict the Future with Python (Forecasting Tutorial)
How to Predict the Future with Python (Forecasting Tutorial)
Dave Ebbelaar
19 How to Use Python Environment Variables
How to Use Python Environment Variables
Dave Ebbelaar
20 7 Data Science Tips for Beginners in 2023
7 Data Science Tips for Beginners in 2023
Dave Ebbelaar
21 How to Effectively Use the Data Science Lifecycle
How to Effectively Use the Data Science Lifecycle
Dave Ebbelaar
22 Full Machine Learning Project — Coding a Fitness Tracker with Python (Part 1)
Full Machine Learning Project — Coding a Fitness Tracker with Python (Part 1)
Dave Ebbelaar
23 Full Machine Learning Project — Processing Raw Data (Part 2)
Full Machine Learning Project — Processing Raw Data (Part 2)
Dave Ebbelaar
24 Full Machine Learning Project — Data Visualization with Matplotlib (Part 3)
Full Machine Learning Project — Data Visualization with Matplotlib (Part 3)
Dave Ebbelaar
25 This Will Change Data Science as We Know It (ChatGPT)
This Will Change Data Science as We Know It (ChatGPT)
Dave Ebbelaar
26 Full Machine Learning Project — Detecting Outliers in Sensor Data (Part 4)
Full Machine Learning Project — Detecting Outliers in Sensor Data (Part 4)
Dave Ebbelaar
27 Full Machine Learning Project — Low-pass Filter & Principal Component Analysis (Part 5a)
Full Machine Learning Project — Low-pass Filter & Principal Component Analysis (Part 5a)
Dave Ebbelaar
28 Full Machine Learning Project — Fourier Transformation & Clustering (Part 5b)
Full Machine Learning Project — Fourier Transformation & Clustering (Part 5b)
Dave Ebbelaar
29 Full Machine Learning Project — Predictive Modelling (Part 6)
Full Machine Learning Project — Predictive Modelling (Part 6)
Dave Ebbelaar
30 Automate Machine Learning with ChatGPT
Automate Machine Learning with ChatGPT
Dave Ebbelaar
31 Scraping Web Datasets for Data Science Projects
Scraping Web Datasets for Data Science Projects
Dave Ebbelaar
32 Full Machine Learning Project — Counting Repetitions (Part 7)
Full Machine Learning Project — Counting Repetitions (Part 7)
Dave Ebbelaar
33 How to Use GitHub Copilot for Data Science (Python + VS Code)
How to Use GitHub Copilot for Data Science (Python + VS Code)
Dave Ebbelaar
Every Beginner Data Scientist Should Understand This
Every Beginner Data Scientist Should Understand This
Dave Ebbelaar
35 Revealing My New AI-Powered Data Science Workflow
Revealing My New AI-Powered Data Science Workflow
Dave Ebbelaar
36 Auto-GPT Tutorial - Create Your Personal AI Assistant 🦾
Auto-GPT Tutorial - Create Your Personal AI Assistant 🦾
Dave Ebbelaar
37 Build Your Own Auto-GPT Apps with LangChain (Python Tutorial)
Build Your Own Auto-GPT Apps with LangChain (Python Tutorial)
Dave Ebbelaar
38 Building Slack AI Assistants with Python & LangChain
Building Slack AI Assistants with Python & LangChain
Dave Ebbelaar
39 ChatGPT Code Interpreter - Goodbye Data Analysts?
ChatGPT Code Interpreter - Goodbye Data Analysts?
Dave Ebbelaar
40 How to Deploy AI Apps to the Cloud with Flask & Azure
How to Deploy AI Apps to the Cloud with Flask & Azure
Dave Ebbelaar
41 How to Build an AI Document Chatbot in 10 Minutes
How to Build an AI Document Chatbot in 10 Minutes
Dave Ebbelaar
42 Is Falcon LLM the OpenAI Alternative? An Experimental Setup with LangChain
Is Falcon LLM the OpenAI Alternative? An Experimental Setup with LangChain
Dave Ebbelaar
43 GPT Engineer... Generate an entire codebase with one prompt
GPT Engineer... Generate an entire codebase with one prompt
Dave Ebbelaar
44 Pandas DataFrame Agent... the future of data analysis?
Pandas DataFrame Agent... the future of data analysis?
Dave Ebbelaar
45 OpenAI Function Calling - Full Beginner Tutorial
OpenAI Function Calling - Full Beginner Tutorial
Dave Ebbelaar
46 How to use ChatGPT's new “Code Interpreter” feature
How to use ChatGPT's new “Code Interpreter” feature
Dave Ebbelaar
47 LangChain just launched their new "LangSmith" platform
LangChain just launched their new "LangSmith" platform
Dave Ebbelaar
48 How I'd Learn AI (if I could start over)
How I'd Learn AI (if I could start over)
Dave Ebbelaar
49 I Used AI To Scrape The Web & Write PDF Reports
I Used AI To Scrape The Web & Write PDF Reports
Dave Ebbelaar
50 LangSmith Tutorial - LLM Evaluation for Beginners
LangSmith Tutorial - LLM Evaluation for Beginners
Dave Ebbelaar
51 7 Lessons for New AI Engineers - Beginner’s Guide
7 Lessons for New AI Engineers - Beginner’s Guide
Dave Ebbelaar
52 The Rise of the "New-Age" Machine Learning Engineer
The Rise of the "New-Age" Machine Learning Engineer
Dave Ebbelaar
53 OpenAI Assistants Tutorial for Beginners
OpenAI Assistants Tutorial for Beginners
Dave Ebbelaar
54 How To Connect OpenAI To WhatsApp (Python Tutorial)
How To Connect OpenAI To WhatsApp (Python Tutorial)
Dave Ebbelaar
55 How to Build Chatbot Interfaces with Python
How to Build Chatbot Interfaces with Python
Dave Ebbelaar
56 PostgreSQL as VectorDB - Beginner Tutorial
PostgreSQL as VectorDB - Beginner Tutorial
Dave Ebbelaar
57 My MacBook Setup (as a coder & business owner)
My MacBook Setup (as a coder & business owner)
Dave Ebbelaar
58 Easiest Way to Connect AI Chatbots to WhatsApp
Easiest Way to Connect AI Chatbots to WhatsApp
Dave Ebbelaar
59 ClickUp Tutorial - What Is ClickUp Brain? 🧠
ClickUp Tutorial - What Is ClickUp Brain? 🧠
Dave Ebbelaar
60 My Development Workflow for Data & AI Projects
My Development Workflow for Data & AI Projects
Dave Ebbelaar

This video teaches beginners the fundamentals of working with Python files, modules, classes, and functions, and how to apply these concepts to prompt engineering. By following along, viewers can learn how to create and manipulate files, import modules, and work with code in an IDE versus a notebook.

Key Takeaways
  1. Create a new Python file and define a function
  2. Import functions from own files using 'from functions import' syntax
  3. Use pip install and documentation to learn PIP libraries
  4. Work with code in an IDE versus a notebook
  5. Transition from single notebooks to multiple files with import statements
💡 Understanding how to work with Python files, modules, classes, and functions is crucial for effective prompt engineering and data science tasks.

Related Reads

📰
Can we truly understand maternal mental health, or are we only measuring it?
Rethinking perinatal mental health research to better understand maternal wellbeing beyond scoring systems
Medium · Deep Learning
📰
How Neuro Linguistic Programming Helps with Anxiety and Stress Management
Learn how Neuro Linguistic Programming (NLP) can help manage anxiety and stress by reframing thoughts and emotions, and why it matters for mental well-being
Medium · NLP
📰
Your Attitude Is the Lens — Change It and the Whole World Looks Different
A positive attitude can transform your life and those around you, making it a crucial aspect of personal and professional growth
Medium · Deep Learning
📰
Mental Models Don’t Just Shape What We Know. They Shape What We Can Learn.
Learn how mental models influence learning and communication to improve your understanding and collaboration with others
Medium · Deep Learning

Chapters (4)

Introduction
1:38 What happens when you run `pip install`
6:49 Files, modules, classes, and functions
9:38 Finding code documentation and examples
Up next
How to Stand Up for Yourself (Even If It Makes You Anxious)
TherapyToThePoint
Watch →