THIS Is How I Write Clean Data Science Code EVERY TIME
Key Takeaways
The video demonstrates how to use the Black package to automatically format Python code according to the PEP8 style guide, and how to integrate it with Visual Studio Code (VS Code) to format code automatically on save.
Full Transcript
hit enter and boom it automatically formats our code everyone welcome to the channel my name is dave and my goal is to help you level up as a data scientist and today i have another exciting new video for you guys in today's video i will show you how i automatically format my python codes for my data science projects i do this with a package that i've recently came across with and it's called black and actually a software developer friend of mine recommended this package to me and i was basically blown away by how awesome this package is and as i said now i use it from a data science project so black is a python code formatter which basically restructures your code according to certain rules this basically ensures that you are following python style guide and the style guide that black uses is the pap8 tau guide which is the most common style guide for for python if you're not familiar with pip8 yet i would highly recommend checking out this website i will leave a link in the description basically in the pip8 style guide there are rules for basically every part of your biting code so there are rules for indentation there are rules for how you structure lists tabs or spaces maximum line lengths etc list goes on and on and a style guide basically ensures that your code is is easy to read and that when you share your code with others they also understand your code and basically everyone is on the same page so black is basically a python package that you can install using pip which i will show you in a bit that you can use to automatically format your code according to pap-8 so that's what i will show you in today's video so let's hop into fierce code and i have an example project open here the first thing you have to do is basically install black which is as easy as running the command pip install black so when i do this now it will say that the requirement is already satisfied but this is how you install black and then basically how black works is you can run the command black and then specify a directory or a file so you can either format whole folders at once or you can do it file by file so what we can do here if we're looking at the example file here which has a pretty long list according to the pip8 style guide lines can only go to a certain length so if we go back to the style guide a maximum line length of 79 characters so this list over here exceeds that maximum length and there are also some other parts within this code that are not in line with the style guide so how this works is we run black and then we link to our python file hit enter and boom it automatically formats our code which is awesome in my opinion so as you can see the list that was previously exceeding the maximum line length is now split up into separate lines so that is easier to read it also created some space between the imports and the start of our code and it also removed a white line here uh from this loop so basically now this whole python file here is in line with the pap8 style guide formatted by black so this is really awesome and what i've just showed you is how to do this manually so for each file for each folder you would have to run this command that i've just showed you whenever you want to format your code but vs code has a really awesome feature to do this automatically and i will now show you how to do that okay so we go to the settings and there are two settings that we have to change the first one is the python formatting provider here you can see python formatting provider and we can choose from auto pep8 black none and another one so here you select black so that's the first setting then we need one more setting that is format on save so editor format on save check this and you can set this at the user level so then from now on every project every new project that you will start in vs code will use these settings and so now if i close out on the settings and here i am within the file and i now hit command s boom it automatically formats the code so that is really convenient in my opinion so then you don't have to open up the terminal and run the command black link to the file path every time you want to format your code now every time you save a file it will be restructured so if i make some changes over here and i hit command s boom it formats it again this basically ensures that you never have to worry about formatting your code again and you can just focus on quote code quality readability and yeah just making your code as good as possible and then black on the back end will fix the formatting for you so this has really helped me out as i said i've been i've enabled this by default within my vs code project so all my python projects all my data science projects will follow the same same style guides and this will make my code easier to read easier to share with others and yeah easy easier to collaborate in that way so that's what i wanted to show you in today's video i hope that you like it if you did please hit the like button subscribe to the channel i'll be making more videos related to python data science and machine learning so if that's something you're interested in you should definitely subscribe it will be fun see in the next one
Original Description
In this video, I will show you how to format Python code automatically for your data science projects with Black. Thanks to this package, you can improve the style and readability of your code without having to worry or think about it. I'll also show you how to change the settings in Visual Code Studio (VS Code) to automatically run Black on saving, so your code is always on point.
Install
- pip install black
VS Code Settings
- Python Formatting Provider — Black
- Format On Save — On
Black
- https://github.com/psf/black
PEP 8 — the Style Guide for Python Code
- https://pep8.org/
Let's Connect
- Instagram | https://instagram.com/daveebbelaar
- LinkedIn | https://linkedin.com/in/daveebbelaar
- Twitter | https://twitter.com/daveebbelaar
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Dave Ebbelaar · Dave Ebbelaar · 7 of 60
1
2
3
4
5
6
▶
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
How to Install Homebrew on Mac (Getting Started)
Dave Ebbelaar
How to Install Python on Mac (Homebrew)
Dave Ebbelaar
How to Install Anaconda on Mac (Getting Started)
Dave Ebbelaar
How to Set up VS Code for Data Science & AI
Dave Ebbelaar
How to Use Git in VS Code for Data Science
Dave Ebbelaar
Data Science Desk Setup to Maximize Productivity
Dave Ebbelaar
THIS Is How I Write Clean Data Science Code EVERY TIME
Dave Ebbelaar
Data Science Tutorial - Project Structure
Dave Ebbelaar
Changing rcParams for Better Data Science Plots | Matplotlib Tutorial
Dave Ebbelaar
How to Read Excel Files with Python (Pandas Tutorial)
Dave Ebbelaar
My Data Science Journey (Zero to Freelance)
Dave Ebbelaar
How I Automate Data Visualization in Python
Dave Ebbelaar
16 Apps I Use Daily as a Data Scientist
Dave Ebbelaar
How to Manage Conda Environments for Data Science
Dave Ebbelaar
How to Export Machine Learning Models in Python
Dave Ebbelaar
VS Code Speed Hack for Data Science
Dave Ebbelaar
17 VS Code Tips That Will Change Your Data Science Workflow
Dave Ebbelaar
How to Predict the Future with Python (Forecasting Tutorial)
Dave Ebbelaar
How to Use Python Environment Variables
Dave Ebbelaar
7 Data Science Tips for Beginners in 2023
Dave Ebbelaar
How to Effectively Use the Data Science Lifecycle
Dave Ebbelaar
Full Machine Learning Project — Coding a Fitness Tracker with Python (Part 1)
Dave Ebbelaar
Full Machine Learning Project — Processing Raw Data (Part 2)
Dave Ebbelaar
Full Machine Learning Project — Data Visualization with Matplotlib (Part 3)
Dave Ebbelaar
This Will Change Data Science as We Know It (ChatGPT)
Dave Ebbelaar
Full Machine Learning Project — Detecting Outliers in Sensor Data (Part 4)
Dave Ebbelaar
Full Machine Learning Project — Low-pass Filter & Principal Component Analysis (Part 5a)
Dave Ebbelaar
Full Machine Learning Project — Fourier Transformation & Clustering (Part 5b)
Dave Ebbelaar
Full Machine Learning Project — Predictive Modelling (Part 6)
Dave Ebbelaar
Automate Machine Learning with ChatGPT
Dave Ebbelaar
Scraping Web Datasets for Data Science Projects
Dave Ebbelaar
Full Machine Learning Project — Counting Repetitions (Part 7)
Dave Ebbelaar
How to Use GitHub Copilot for Data Science (Python + VS Code)
Dave Ebbelaar
Every Beginner Data Scientist Should Understand This
Dave Ebbelaar
Revealing My New AI-Powered Data Science Workflow
Dave Ebbelaar
Auto-GPT Tutorial - Create Your Personal AI Assistant 🦾
Dave Ebbelaar
Build Your Own Auto-GPT Apps with LangChain (Python Tutorial)
Dave Ebbelaar
Building Slack AI Assistants with Python & LangChain
Dave Ebbelaar
ChatGPT Code Interpreter - Goodbye Data Analysts?
Dave Ebbelaar
How to Deploy AI Apps to the Cloud with Flask & Azure
Dave Ebbelaar
How to Build an AI Document Chatbot in 10 Minutes
Dave Ebbelaar
Is Falcon LLM the OpenAI Alternative? An Experimental Setup with LangChain
Dave Ebbelaar
GPT Engineer... Generate an entire codebase with one prompt
Dave Ebbelaar
Pandas DataFrame Agent... the future of data analysis?
Dave Ebbelaar
OpenAI Function Calling - Full Beginner Tutorial
Dave Ebbelaar
How to use ChatGPT's new “Code Interpreter” feature
Dave Ebbelaar
LangChain just launched their new "LangSmith" platform
Dave Ebbelaar
How I'd Learn AI (if I could start over)
Dave Ebbelaar
I Used AI To Scrape The Web & Write PDF Reports
Dave Ebbelaar
LangSmith Tutorial - LLM Evaluation for Beginners
Dave Ebbelaar
7 Lessons for New AI Engineers - Beginner’s Guide
Dave Ebbelaar
The Rise of the "New-Age" Machine Learning Engineer
Dave Ebbelaar
OpenAI Assistants Tutorial for Beginners
Dave Ebbelaar
How To Connect OpenAI To WhatsApp (Python Tutorial)
Dave Ebbelaar
How to Build Chatbot Interfaces with Python
Dave Ebbelaar
PostgreSQL as VectorDB - Beginner Tutorial
Dave Ebbelaar
My MacBook Setup (as a coder & business owner)
Dave Ebbelaar
Easiest Way to Connect AI Chatbots to WhatsApp
Dave Ebbelaar
ClickUp Tutorial - What Is ClickUp Brain? 🧠
Dave Ebbelaar
My Development Workflow for Data & AI Projects
Dave Ebbelaar
More on: AI-Assisted Code Review
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
5 prompt engineering techniques to get the best out of a legacy project
Dev.to · Marco Coelho
The Real Reason Prompt Engineering Isn't Going Away
Dev.to AI
Common Prompt Engineering Mistakes and How to Avoid Them
Medium · ChatGPT
Day 5: Prompt Engineering Basics (For DevOps & Cloud Engineers)
Medium · AI
🎓
Tutor Explanation
DeepCamp AI